#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;
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 |
53 ms |
7764 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 |
2 ms |
2524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
3676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
6672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
7512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
7508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
8184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
8024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
8780 KB |
Output is correct |