#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;
sort(a +1, a + n + 1);
int l = n + 1;
for (int x = 1;x <= n;x++) {
if (a[x] >= h) {
l = x;
break;
}
}
for (int i = l, j = 1;i <= n && j <= c;i++,j++)
a[i]++;
// 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 ans = 0;
for (int i = 1;i <= n;i++)
ans += (a[i] >= l && a[i] <= r);
cout << ans << '\n';
// 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
4544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Correct |
544 ms |
3416 KB |
Output is correct |
6 |
Correct |
632 ms |
3668 KB |
Output is correct |
7 |
Correct |
201 ms |
2576 KB |
Output is correct |
8 |
Correct |
307 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
846 ms |
3152 KB |
Output is correct |
2 |
Correct |
988 ms |
3784 KB |
Output is correct |
3 |
Correct |
28 ms |
2396 KB |
Output is correct |
4 |
Correct |
493 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
812 ms |
3156 KB |
Output is correct |
2 |
Execution timed out |
1031 ms |
4084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1056 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1041 ms |
4544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
4560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1074 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1036 ms |
4440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |