#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, q;
int a[100005];
struct seg{
int tree[270000], lazy[270000];
void lazydown(int p){
tree[2*p] += lazy[p];
tree[2*p+1] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
void add(int s, int e, int ps, int pe, int p, int v){
if(e < ps || pe < s) return;
if(s <= ps && pe <= e){
tree[p] += v;
lazy[p] += v;
return;
}
int pm = (ps + pe) / 2;
lazydown(p);
add(s,e,ps,pm,2*p,v);
add(s,e,pm+1,pe,2*p+1,v);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
int lower_bound(int ps, int pe, int p, int val){
if(tree[1] < val) return n+1;
if(ps == pe) return ps;
int pm = (ps + pe) / 2;
lazydown(p);
if(tree[2*p] < val) return lower_bound(pm+1,pe,2*p+1,val);
else return lower_bound(ps,pm,2*p,val);
}
int getval(int pos, int ps, int pe, int p){
if(ps == pe) return tree[p];
int pm = (ps + pe) / 2;
lazydown(p);
if(pos <= pm) return getval(pos,ps,pm,2*p);
return getval(pos,pm+1,pe,2*p+1);
}
void dfs(int ps, int pe, int p){
if(ps == pe){
printf("%d ",tree[p]);
return;
}
lazydown(p);
dfs(ps,(ps+pe)/2,2*p);
dfs((ps+pe)/2+1,pe,2*p+1);
}
}seg;
int main(){
scanf("%d %d",&n,&q);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
for(int i=1; i<=n; i++){
seg.add(i,i,1,n,1,a[i]);
}
while(q--){
char str[5];
int x, y;
scanf("%s %d %d",str,&y,&x);
if(str[0] == 'F'){
int st = seg.lower_bound(1,n,1,x);
if(st == n+1) continue;
int ed = min(st + y - 1, n);
int val = seg.getval(ed,1,n,1);
int t = seg.lower_bound(1,n,1,val);
int cnt = ed - t + 1;
int u = seg.lower_bound(1,n,1,val + 1);
seg.add(st, t - 1, 1, n, 1, 1);
seg.add(u - cnt, u - 1, 1, n, 1, 1);
}
else{
swap(x,y);
int t = seg.lower_bound(1,n,1,y+1);
int u = seg.lower_bound(1,n,1,x);
printf("%d\n",t - u);
}
}
}
Compilation message
grow.cpp: In function 'int main()':
grow.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
58 | scanf("%d %d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~~
grow.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
60 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
grow.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
69 | scanf("%s %d %d",str,&y,&x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
3988 KB |
Output is correct |
2 |
Correct |
155 ms |
4420 KB |
Output is correct |
3 |
Correct |
145 ms |
4356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
304 KB |
Output is correct |
5 |
Correct |
50 ms |
1464 KB |
Output is correct |
6 |
Correct |
69 ms |
1632 KB |
Output is correct |
7 |
Correct |
8 ms |
460 KB |
Output is correct |
8 |
Correct |
36 ms |
1216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
1760 KB |
Output is correct |
2 |
Correct |
60 ms |
1832 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
43 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1952 KB |
Output is correct |
2 |
Correct |
71 ms |
1720 KB |
Output is correct |
3 |
Correct |
13 ms |
548 KB |
Output is correct |
4 |
Correct |
62 ms |
1844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2696 KB |
Output is correct |
2 |
Correct |
138 ms |
3908 KB |
Output is correct |
3 |
Correct |
21 ms |
1208 KB |
Output is correct |
4 |
Correct |
115 ms |
3996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
3780 KB |
Output is correct |
2 |
Correct |
150 ms |
4052 KB |
Output is correct |
3 |
Correct |
139 ms |
4244 KB |
Output is correct |
4 |
Correct |
22 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
3824 KB |
Output is correct |
2 |
Correct |
108 ms |
4028 KB |
Output is correct |
3 |
Correct |
141 ms |
4264 KB |
Output is correct |
4 |
Correct |
20 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
4316 KB |
Output is correct |
2 |
Correct |
139 ms |
3960 KB |
Output is correct |
3 |
Correct |
60 ms |
3360 KB |
Output is correct |
4 |
Correct |
102 ms |
3760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
4224 KB |
Output is correct |
2 |
Correct |
141 ms |
4356 KB |
Output is correct |
3 |
Correct |
205 ms |
4488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
5000 KB |
Output is correct |