# 10116 "through a 4.1 Exercise 1" head count

1538: The number of inventory


Time limit: 200 ms Memory Limit: 524288 KB
Submissions: 920 number by: 204 

Description [title]

NK high school students to organize five clouds cottage participate in social practice is customary to take a train to. As many NK middle school students must be counted a good number of people before the train.

Initially, no students on the train. When students begin to train, senior director of the departure went the last carriage from the first car, each car are likely to have the students up and down at any time. Senior director went to the first  m when m cars, he wanted to know before  m a m on how many students there are cars, but he did not turn around and go back habits. That every time he questions, m m always a larger than before.

[Enter]

The first line of two integers  the n- , k the n-, k, it represents a total train  the n- the n-carriages and  k k events.

Then there are  K K line, given in chronological  K K events, the beginning of each row has a letter  A A, B B or  C C.

If the letters  A A, followed by a number  m m, now it represents the first grade director  m m carriages;

If the letter is  B B, followed by two numbers  m , the p- m, the p-, he said in the first  m m carriages have  the p- the p-students on the bus;

If the letter is  C C, followed by two numbers  m , the p- m, the p-, said in the first  m m carriages have  the p- the p-students get off.

The total number of students does not exceed  10 5 105

[Output]

For each  A A, output line, an integer that represents the answer to question senior director.

[Sample input]

10 7
A 1
B 1 1
B 3 1
B 4 1
A 2
A 3
A 10

[Sample Output]

0
1
2
3

【prompt】

Data range and tips:

For 30% of the data, . 1 n- , K 10 . 4 1 ≦ n, k≤104, at least  3000 3000  A A;

To 100% of the data, . 1 n- . 5 × 10 . 5 , . 1 K 10 . 5 1≤n≤5 × 105,1≤k≤105, at least  . 3 × 10 . 4 . 3 × 104 th  A A.

【source】


no

 

#include<bits/stdc++.h>
using namespace std;
int a[500005]; int n,k; int Add(int x,int p){ for(;x<=n;x+=x&(-x))a[x]+=p; } int Que(int x){ int res=0; for(;x>0;x-=x&(-x))res+=a[x]; return res; } int main(){ //freopen("test.in","r",stdin); scanf("%d%d",&n,&k); while(k--){ char op;int m,p; for(op=getchar();op<'A'||op>'C';op=getchar()); if(op=='A'){ scanf("%d",&m); printf("%d\n",Que(m)); } else{ scanf("%d%d",&m,&p); if(op=='C')p=-p; Add(m,p); } } return 0; }

 

Guess you like

Origin www.cnblogs.com/fdezlsq/p/11432285.html