HDU 4288 Coder

Source: Internet
Author: User

Codertime limit:10000msmemory limit:32768kbthis problem'll be judged onHDU. Original id:4288
64-bit integer IO format: %i64d Java class name: Main 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 was 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/AlgorithmInputThere ' 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).
OutputFor each operation "sum" tab, print one line containing exactly one integer denoting the digest sum of the current 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
345
HintC + + maybe run faster than g++ in this problem.SourceACM/ICPC Asia Regional Chengdu Online Problem Solving: line tree, Orz sum[i] can be calculated, (let the left element number%5 + k%5)%5 = I can solve K
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMAXN =100010;5 structnode{6     intlt,rt,cnt;7LL sum[5];8}tree[maxn<<2];9 voidBuildintLtintRtintv) {Tentree[v].lt =lt; OneTree[v].rt =RT; Atree[v].cnt =0; -memset (Tree[v].sum,0,sizeoftree[v].sum); -     if(LT = = RT)return; the     intMid = (lt + rt) >>1; -Build (lt,mid,v<<1); -Build (mid+1,rt,v<<1|1); - } + voidPushup (intv) { -      for(inti =0; I <5; ++i) { +         intTMP = ((i-tree[v<<1].cnt%5)%5+5)%5; ATree[v].sum[i] = tree[v<<1].sum[i] + tree[v<<1|1].sum[tmp]; at     } - } - voidUpdateintPintValintDeltaintv) { -Tree[v].cnt + =Delta; -     if(tree[v].lt = =tree[v].rt) { -tree[v].sum[0] + = (LL) delta*Val; in         return; -     } to     intMid = (tree[v].lt + tree[v].rt) >>1; +     if(P <= mid) update (p,val,delta,v<<1); -     ElseUpdate (p,val,delta,v<<1|1); the Pushup (v); * } $ intLi[maxn],q[maxn],tot,n;Panax Notoginseng Charstr[maxn][Ten]; - intMain () { the      while(~SCANF ("%d",&N)) { +          for(inti = tot =0; I < n; ++i) { Ascanf"%s", Str[i]); the             if(str[i][0] !='s'){ +scanf"%d", q+i); -li[tot++] =Q[i]; $             } $         } -Sort (li,li+tot); -tot = unique (li,li+tot)-Li; theBuild1Tot1); -          for(inti =0; I < n; ++i) {Wuyi             intp = lower_bound (Li,li + tot,q[i])-Li; the             if(str[i][0] =='a') Update (P +1, Q[i],1,1); -             Else if(str[i][0] =='D') Update (P +1, q[i],-1,1); Wu             Elseprintf"%i64d\n", tree[1].sum[2]); -         } About     } $     return 0; -}
View Code

HDU 4288 Coder

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.