#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << "," << p.second << ")"; return o;}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";for(auto e:x)o<< e << ", ";return o<<"}";}
#define debug(X) cerr << "["#X"]:" << X << '\n';
#else
#define debug(X) ;
#endif
#define ll long long
#define all(x) (x).begin(), (x).end()
#define cerr if(0)cout
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(all(a));
int base = 1;
while (base < n) base *= 2;
struct Node {
int mx, lazy;
Node() {
mx = lazy = 0;
}
};
vector<Node> tree(2*base);
for (int i = 0; i < n; i++) {
tree[base+i].mx = a[i];
}
for (int i = base-1; i >= 1; i--) {
tree[i].mx = max(tree[2*i].mx, tree[2*i+1].mx);
}
auto push_to_sons = [&](int v) {
if (tree[v].lazy == 0) return;
int x = tree[v].lazy;
tree[2*v].mx += x;
tree[2*v+1].mx += x;
tree[2*v].lazy += x;
tree[2*v+1].lazy += x;
tree[v].lazy = 0;
};
function<void(int, int, int, int, int, int)> update = [&](int l, int r, int x, int v, int a, int b) {
if (r < a || b < l) return;
if (l <= a && b <= r) {
tree[v].mx += x;
tree[v].lazy += x;
return;
}
push_to_sons(v);
int mid = (a+b)/2;
update(l, r, x, 2*v, a, mid); update(l, r, x, 2*v+1, mid+1, b);
tree[v].mx = max(tree[2*v].mx, tree[2*v+1].mx);
};
function<int(int, int, int, int)> find = [&](int x, int v, int a, int b) {
if (tree[v].mx < x) return -1;
if (a == b) return a;
push_to_sons(v);
int mid = (a+b)/2;
int y = find(x, 2*v, a, mid);
if (y != -1) return y;
return find(x, 2*v+1, mid+1, b);
};
function<int(int, int, int, int)> find2 = [&](int x, int v, int a, int b) {
if (tree[v].mx <= x) return -1;
if (a == b) return a;
push_to_sons(v);
int mid = (a+b)/2;
int y = find2(x, 2*v, a, mid);
if (y != -1) return y;
return find2(x, 2*v+1, mid+1, b);
};
function<int(int, int, int, int)> val = [&](int x, int v, int a, int b) {
if (a == b) return tree[v].mx;
push_to_sons(v);
int mid = (a+b)/2;
if (x <= mid) return val(x, 2*v, a, mid);
else return val(x, 2*v+1, mid+1, b);
};
auto print = [&]() {
for (int i = 1; i < 2*base; i++) {
if (i < base) push_to_sons(i);
cerr << "(" << tree[i].mx << ", " << tree[i].lazy << ") ";
}
cerr << '\n';
return;
};
while (m--) {
char c;
cin >> c;
if (c == 'F') {
int c, h;
cin >> c >> h;
int idx = find(h, 1, 0, base-1);
cerr << "FFF " << idx << '\n';
if (idx == -1) continue;
int end = min(n-1, idx+c-1);
int fi = find(val(end, 1, 0, base-1), 1, 0, base-1);
int last = find2(val(end, 1, 0, base-1), 1, 0, base-1)-1;
if (last == -2) last = n-1;
cerr << "val: " << val(end, 1, 0, base-1) << '\n';
cerr << "fi: " << fi << '\n';
cerr << "last: " << last << '\n';
if (idx != fi) {
update(idx, fi-1, 1, 1, 0, base-1);
update(max(fi, last-(c-(fi-idx))+1), last, 1, 1, 0, base-1);
}
else {
update(max(fi, last-c+1), last, 1, 1, 0, base-1);
}
print();
}
else {
int minn, maxx;
cin >> minn >> maxx;
int low = find(minn, 1, 0, base-1), up = find2(maxx, 1, 0, base-1);
cerr << low << ' ' << up << '\n';
if (low == -1) {cout << 0 << '\n'; continue;}
if (up == -1) {cout << n-low << '\n'; continue;}
up--;
cout << up-low+1 << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
2768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
88 ms |
1460 KB |
Output is correct |
6 |
Correct |
104 ms |
1740 KB |
Output is correct |
7 |
Correct |
32 ms |
560 KB |
Output is correct |
8 |
Correct |
30 ms |
1172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
844 KB |
Output is correct |
2 |
Correct |
130 ms |
1856 KB |
Output is correct |
3 |
Correct |
10 ms |
632 KB |
Output is correct |
4 |
Correct |
40 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
892 KB |
Output is correct |
2 |
Correct |
130 ms |
1708 KB |
Output is correct |
3 |
Correct |
103 ms |
596 KB |
Output is correct |
4 |
Correct |
108 ms |
1852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1036 ms |
1728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1056 ms |
2668 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1053 ms |
2836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1042 ms |
2764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1050 ms |
2860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
3176 KB |
Output is correct |