#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e5 + 100;
int a[N], seg[N * 4], laz[N * 4];
void push(int id) {
int t = laz[id];
laz[id * 2] += t;
laz[id * 2 + 1] += t;
seg[id * 2] += t;
seg[id * 2 + 1] += t;
laz[id] = 0;
}
void upd(int id, int l, int r, int u, int v, int c) {
if (l > v || r < u || u > v)
return;
if (l >= u && r <= v) {
seg[id] += c;
laz[id] += c;
return;
}
push(id);
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, c);
upd(id * 2 + 1, m + 1, r, u, v, c);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
int get(int id, int l, int r, int p) {
if (l == r)
return seg[id];
push(id);
int m = (l + r) / 2;
if (m >= p)
return get(id * 2, l, m, p);
return get(id * 2 + 1, m + 1, r, p);
}
int n;
int find(int id, int l, int r, int k) {
if (seg[id] < k)
return r + 1;
if (l == r)
return l;
int m = (l + r) / 2;
push(id);
if (seg[id * 2] >= k)
return find(id * 2, l, m, k);
return find(id * 2 + 1, m + 1, r, k);
}
int num(int l, int r) {
return find(1, 1, n, r + 1) - find(1, 1, n, l);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
upd(1, 1, n, i, i, a[i]);
}
for (int i = 1; i <= m; i++) {
char c;
cin >> c;
if (c == 'F') {
int c, h;
cin >> c >> h;
int l = find(1, 1, n, h);
if (l + c - 1 >= n) {
upd(1, 1, n, l, n, 1);
} else {
int r = l + c - 1;
int val = get(1, 1, n, r);
int lst = find(1, 1, n, val + 1) - 1;
int f = find(1, 1, n, val);
upd(1, 1, n, l, f - 1, 1);
int remain = (c - (f - l));
upd(1, 1, n, lst - remain + 1, lst, 1);
}
} else {
int l, r;
cin >> l >> r;
cout << num(l, r) << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
7236 KB |
Output is correct |
2 |
Correct |
98 ms |
8780 KB |
Output is correct |
3 |
Correct |
44 ms |
8504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
32 ms |
5636 KB |
Output is correct |
6 |
Correct |
38 ms |
5712 KB |
Output is correct |
7 |
Correct |
4 ms |
4700 KB |
Output is correct |
8 |
Correct |
20 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
4956 KB |
Output is correct |
2 |
Correct |
38 ms |
5984 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
27 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4948 KB |
Output is correct |
2 |
Correct |
40 ms |
5716 KB |
Output is correct |
3 |
Correct |
9 ms |
4700 KB |
Output is correct |
4 |
Correct |
43 ms |
5812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7004 KB |
Output is correct |
2 |
Correct |
92 ms |
8524 KB |
Output is correct |
3 |
Correct |
14 ms |
7204 KB |
Output is correct |
4 |
Correct |
36 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
7076 KB |
Output is correct |
2 |
Correct |
84 ms |
8252 KB |
Output is correct |
3 |
Correct |
40 ms |
8632 KB |
Output is correct |
4 |
Correct |
18 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
7004 KB |
Output is correct |
2 |
Correct |
72 ms |
8272 KB |
Output is correct |
3 |
Correct |
41 ms |
8528 KB |
Output is correct |
4 |
Correct |
13 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
7260 KB |
Output is correct |
2 |
Correct |
86 ms |
8272 KB |
Output is correct |
3 |
Correct |
36 ms |
7700 KB |
Output is correct |
4 |
Correct |
61 ms |
8032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
7092 KB |
Output is correct |
2 |
Correct |
97 ms |
8528 KB |
Output is correct |
3 |
Correct |
139 ms |
8884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
7504 KB |
Output is correct |