#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define pii pair <int,int>
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define int ll // ?
using namespace std;
const int N = 1e5 + 5,inf = 1e9;
int t[4*N],lz[4*N],a[N];
void push(int h){
if (lz[h] == 0) return;
lz[h*2] += lz[h];
lz[h*2 + 1] += lz[h];
t[h*2] += lz[h];
t[h*2 + 1] += lz[h];
lz[h] =0;
}
void build(int h,int l,int r){
if (l == r){
t[h] = a[l];
return;
}
build(left),build(right);
t[h] = max(t[h*2],t[h*2 + 1]);
}
int get(int h,int l,int r,int idx){
if (l == r){
return t[h];
}
push(h);
int mid = (l + r)/2;
if (idx > mid) return get(right,idx);
return get(left,idx);
}
void upd(int h,int l,int r,int L,int R,int val){
if (r < L || R < l) return;
if (L <= l && r <= R){
t[h] += val;
lz[h] += val;
return;
}
push(h);
upd(left,L,R,val);
upd(right,L,R,val);
t[h] = max(t[h*2],t[h*2 + 1]);
}
int find(int h,int l,int r,int H){
if (l == r) {
if (t[h] < H) return 0;
return l;
}
push(h);
if (t[h*2] >= H) return find(left,H);
return find(right,H);
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,Q;
cin>>n>>Q;
for (int i = 1; i <= n; i++){
cin>>a[i];
}
sort(a+1,a+n+1);
build(1,1,n);
while (Q--){
char c;
cin>>c;
if (c == 'C'){
int le,ri;
cin>>le>>ri;
if (t[1] < le) {
cout<<0<<endl;
continue;
}
int l = find(1,1,n,le); // pirvelive le ze meti an tolis indexi
int r = find(1,1,n,ri + 1) - 1;
if (t[1] <= ri) r = n;
cout<<r - l + 1<<"\n";
}else{
int x,h;
cin>>x>>h;
if (t[1] < h) continue;
int l = find(1,1,n,h),r = l + x - 1;
int val = get(1,1,n,r);
int rr = find(1,1,n,val) - 1;
upd(1,1,n,l,rr,1);
x -= (rr - l + 1);
r = find(1,1,n,val + 1) - 1;
if (t[1] < val + 1) r = n;
upd(1,1,n,r - x + 1,r,1);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
5184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
2948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
5056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
5148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
5224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
5608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |