#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e5 + 69;
int st[4 * maxn], n, q, a[maxn], lz[4 * maxn];
void push(int v) {
if (lz[v]) {
st[v * 2] += lz[v];
st[v * 2 + 1] += lz[v];
lz[v * 2] += lz[v];
lz[v * 2 + 1] += lz[v];
lz[v] = 0;
}
}
void build(int v, int tl, int tr) {
if (tl == tr)
st[v] = a[tl];
else {
int mid = (tl + tr) / 2;
build(v * 2, tl, mid);
build(v * 2 + 1, mid + 1, tr);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
void upd(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r) {
st[v]++;
lz[v]++;
}
else {
int mid = (tl + tr) / 2;
push(v);
upd(v * 2, tl, mid, l, r);
upd(v * 2 + 1, mid + 1, tr, l, r);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
int qry(int v, int tl, int tr, int x) {
if (tl == tr)
return tl;
else {
push(v);
int mid = (tl + tr) / 2;
if (st[v * 2] >= x)
return qry(v * 2, tl, mid, x);
else
return qry(v * 2 + 1, mid + 1, tr, x);
}
}
int qryind(int v, int tl, int tr, int p) {
if (tl == tr)
return st[v];
else {
push(v);
int mid = (tl + tr) / 2;
if (mid >= p)
return qryind(v * 2, tl, mid, p);
else
return qryind(v * 2 + 1, mid + 1, tr, p);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
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 t;
cin >> t;
if (t == 'F') {
int c, h;
cin >> c >> h;
if (st[1] < h)
continue;
int l = qry(1, 1, n, h);
int r = min(n, l + c - 1);
int x = qryind(1, 1, n, r);
int y = -1;
if (r < n)
y = qryind(1, 1, n, r + 1);
if (x == y) {
int z = max(l, qry(1, 1, n, x));
int raz = r - z + 1;
int p = qry(1, 1, n, x + 1);
if (z > l)
upd(1, 1, n, l, z - 1);
upd(1, 1, n, p - raz, p - 1);
}
else
upd(1, 1, n, l, r);
}
else {
int l, r;
cin >> l >> r;
int x = n + 1, y = n + 1;
if (st[1] >= r + 1)
x = qry(1, 1, n, r + 1);
if (st[1] >= l)
y = qry(1, 1, n, l);
cout << x - y << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
6656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
2832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
5464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
6628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
6592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
6736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
6708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
6992 KB |
Output is correct |