#include <bits/stdc++.h>
using namespace std;
#define int long long int
int arr[100005], seg[4*100005], lazy[4*100005];
void lazypropagate(int n, int l, int r) {
if (lazy[n]) {
seg[n] += lazy[n];
if (l != r) {
lazy[2*n] += lazy[n];
lazy[2*n+1] += lazy[n];
}
lazy[n] = 0;
}
}
void build(int n, int l, int r) {
if (l == r) {
seg[n] = arr[l];
} else {
int m = (l+r)/2;
build(2*n, l, m);
build(2*n+1, m+1, r);
seg[n] = max(seg[2*n], seg[2*n+1]);
}
}
void update(int n, int l, int r, int a, int b, int v) {
lazypropagate(n, l, r);
if (b < l || r < a) {
return;
} else if (a <= l && r <= b) {
lazy[n] = v;
lazypropagate(n, l, r);
} else {
int m = (l+r)/2;
update(2*n, l, m, a, b, v);
update(2*n+1, m+1, r, a, b, v);
seg[n] = max(seg[2*n], seg[2*n+1]);
}
}
int query(int n, int l, int r, int a, int b) {
if (b < l || r < a) {
return 0;
}
lazypropagate(n, l, r);
if (a <= l && r <= b) {
return seg[n];
} else {
int m = (l+r)/2;
return max(query(2*n, l, m, a, b), query(2*n+1, m+1, r, a, b));
}
}
int search(int n, int h) {
int l = 0, r = n-1;
while(l < r) {
int m = (l+r)/2, v;
v = query(1, 0, n-1, m, m);
if (v >= h) {
r = m;
} else {
l = m+1;
}
}
if (query(1, 0, n-1, l, l) < h) {
return n;
}
return l;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
arr[i] = a[i];
}
build(1, 0, n-1);
while(m--) {
char ch;
cin >> ch;
if (ch == 'F') {
int c, h, ind1, ind2, ind3, hm;
cin >> c >> h;
ind1 = search(n, h);
if (ind1 == n) {
continue;
}
if (ind1+c >= n) {
update(1, 0, n-1, ind1, n-1, 1);
continue;
}
hm = query(1, 0, n-1, ind1+c-1, ind1+c-1);
ind2 = search(n, hm);
if (ind1 == ind2) {
ind3 = search(n, hm+1);
update(1, 0, n-1, ind3-c, ind3-1, 1);
continue;
}
update(1, 0, n-1, ind1, ind2-1, 1);
c -= ind2-ind1;
ind3 = search(n, hm+1);
update(1, 0, n-1, ind3-c, ind3-1, 1);
} else {
int mn, mx;
cin >> mn >> mx;
if (search(n, mx) == n) {
cout << search(n, mx)-search(n, mn) << endl;
} else {
cout << search(n, mx)-search(n, mn)+1 << endl;
}
}
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
489 ms |
9080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
431 ms |
5764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
448 ms |
4104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
491 ms |
7436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
521 ms |
7740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
548 ms |
8924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
692 ms |
8528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
621 ms |
9156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
767 ms |
9296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |