Hangzhou Electric HDU ACM Coder (STL)

Source: Internet
Author: User


Welcome to the Bestcoder-every Saturday night (with rice!) )
Coder Time limit:20000/10000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4200 Accepted Submission (s): 1630


Problem Description in mathematics and computer science, an algorithm describes a set of procedures or instructions that Define a procedure. The term has become increasing popular since the advent of cheap and reliable computers. Many companies now employ a single coder to write an algorithm that would replace many other employees. An added benefit to the employer was that the coder would also become redundant once their work is done.1
You is now the Signle coder, and has been assigned a new task writing code, since your boss would like to replace many O Ther employees (and you are become redundant once your task is complete).
Your code should is able to complete a task to replace these employees who does nothing all day but eating:make the digest Sum.
By saying "Digest sum" we study some properties of data. For the sake of simplicity, we data is a set of integers. Your code should give response to following operations:
1. Add X–add the element x to the set;
2. del X–remove the element x from the set;
3. Sum–find the digest sum of the set. The digest sum should is understood by

Where the set S is written as {A1, A2, ..., AK} satisfying A1 < A2 < A3 < ... < AK
Can you complete the This task (and is then fired)?
------------------------------------------------------------------------------
1 See Http://uncyclopedia.wikia.com/wiki/Algorithm
Input there ' re several test cases.
The first line contains one integer n (1 <= n <=), and the number of operations to process.
Then following are n lines, each one containing one of the three operations: "Add X" or "Del x" or "sum".
Assume that 1 <= x <= 109.
Please see the sample for detailed format.
For any "add X" It's guaranteed that's currently in the set just before this operation.
For any "Del X" it's guaranteed that x must currently are in the set just before this operation.
Please process until EOF (End of File).

Output for each operation "sum" tab print one line containing exactly one integer denoting the digest sum of the Curre NT set. Print 0 If the set is empty.

Sample Input
9add 1add 2add 3add 4add 5sumadd 6del 3sum6add 1add 3add 5add 7add 9sum

Sample Output
345HintC + + maybe run faster than g++ in this problem. The topic has been tangled for a long time, the line tree version of the online problem is not very detailed, it may be strange I can not understand .... Violence vector Step-by-step simulation like can pass, muddle through, after the line tree level deepened later, and then back to write a line tree version hope ~ Learn to debug code with vim for the first time. Feel OK ~ Just a lot of many usages are still not mastered, VI of the powerful display does not open it ~! , is not want to be a glare of the VIMRC configuration? If you want to personalize, you can contact me. Okay, AC code, water over: 
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include < string.h> #include <cctype> #include <string> #include <cmath> #include <vector> #include <stack> #include <queue> #include <map> #include <set> using namespace std;    Vector<int>cnt;int N;int Main () {char op[5];          while (scanf ("%d", &n)! = EOF) {for (int i = 0;i < n; i++) {scanf ("%s", op);              if (op[0] = = ' a ') {int x;scanf ("%d", &x);          Cnt.insert (Lower_bound (Cnt.begin (), Cnt.end (), x), x);                             } else if (op[0] = = ' d ') {int x;scanf ("%d", &x);          Cnt.erase (Lower_bound (Cnt.begin (), Cnt.end (), x));              } else {long long ans = 0;              for (int i = 2; I < cnt.size (); i+=5) {ans + = cnt[i];          } printf ("%lld\n", ans); }} CNt.clear (); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hangzhou Electric HDU ACM Coder (STL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.