#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5+5;
int N,M,A[MAX],T[4*MAX];
void upt(int l, int r, int st, int en, int pos, int val){
if(en<l || st>r) return;
if(l<=st && en<=r){
T[pos] += val;
return;
}
upt(l,r,st,(st+en)/2,pos*2,val);
upt(l,r,(st+en)/2+1,en,pos*2+1,val);
}
int get(int x, int st, int en, int pos){
if(en<x || st>x) return 0;
if(st==en) return T[pos];
return T[pos]+get(x,st,(st+en)/2,2*pos)+get(x,(st+en)/2+1,en,2*pos+1);
}
int sear(int h, int st, int en){
if(st==en) return st;
if(get((st+en)/2,1,N,1)>=h) return sear(h,st,(st+en)/2);
else return sear(h,(st+en)/2+1,en);
}
int main()
{
cin >> N >> M;
for(int i=1; i<=N; i++) cin >> A[i];
sort(A+1,A+N+1);
for(int i=1; i<=N; i++) upt(i,i,1,N,1,A[i]);
for(int i=0; i<M; i++){
char O;
int x,y;
cin >> O >> x >> y;
if(O=='F'){
int a = sear(y,1,N+1);
int h = get(a+x-1,1,N,1);
int b = sear(h,1,N+1);
upt(a,b-1,1,N,1,1);
int d = sear(h+1,1,N+1);
upt(d-a-x+b,d-1,1,N,1,1);
}
if(O=='C'){
cout << sear(y+1,1,N+1)-sear(x,1,N+1) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
376 ms |
2924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
13 ms |
376 KB |
Output is correct |
3 |
Incorrect |
14 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
343 ms |
1528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
345 ms |
1848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
375 ms |
2184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
386 ms |
2700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
405 ms |
2740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
616 ms |
3476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
506 ms |
3132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
627 ms |
4004 KB |
Output isn't correct |