#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1e9 + 7, maxn = 1e5 + 5, inf = 1e18 + 5;
int seg[maxn << 2], n, h[maxn], lazy[maxn << 2];
void pull(int x, int k){
seg[x] += k;
lazy[x] += k;
}
void shift(int x){
pull(x << 1, lazy[x]);
pull(x << 1 | 1, lazy[x]);
lazy[x] = 0;
}
void upd(int l, int r, int x = 1, int lx = 0, int rx = n){
if(l <= lx && r >= rx){
pull(x, 1);
return;
} if(l >= rx || r <= lx) return;
shift(x);
int mid = (lx + rx) >> 1;
upd(l, r, x << 1, lx, mid);
upd(l, r, x << 1 | 1, mid, rx);
seg[x] = max(seg[x << 1], seg[x << 1 | 1]);
}
int query(int k, int x = 1, int lx = 0, int rx = n){
if(lx + 1 == rx) {
if(seg[x] > k) return lx;
else return rx;
}
shift(x);
int mid = (lx + rx) >> 1;
if(seg[x << 1] > k) return query(k, x << 1, lx, mid);
return query(k, x << 1 | 1, mid, rx);
}
int get(int i, int x = 1, int lx = 0, int rx = n){
if(lx + 1 == rx) return seg[x];
shift(x);
int mid = (lx + rx) >> 1;
if(i < mid) return get(i, x << 1, lx, mid);
return get(i, x << 1 | 1, mid, rx);
}
void build(int x = 1, int lx = 0, int rx = n){
if(lx + 1 == rx){
seg[x] = h[lx];
return;
}
int mid = (lx + rx) >> 1;
build(x << 1, lx, mid);
build(x << 1 | 1, mid, rx);
seg[x] = max(seg[x << 1], seg[x << 1 | 1]);
}
int main(){
int q; cin >> n >> q;
for(int i = 0; i < n; i++) cin >> h[i];
sort(h, h + n);
build();
while(q--){
char t; cin >> t;
if(t == 'F'){
int c, h; cin >> c >> h;
int fst = query(h - 1);
int en = min(fst + c - 1, n - 1);
int val = get(en);
int l_val = query(val-1), r_val = query(val);
if(fst < l_val) upd(fst, l_val);
int k = en - l_val + 1;
upd(r_val - k, r_val);
}else{
int l, r; cin >> l >> r;
cout << query(r) - query(l - 1) << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
184 ms |
2776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
360 KB |
Output is correct |
3 |
Correct |
8 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Correct |
167 ms |
580 KB |
Output is correct |
6 |
Incorrect |
214 ms |
684 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
209 ms |
708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
200 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
1580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
165 ms |
2792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
157 ms |
2880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
2748 KB |
Output is correct |
2 |
Incorrect |
200 ms |
2756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
194 ms |
2944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
3244 KB |
Output is correct |