#include <bits/stdc++.h>
#define FOR(i,x,n) for(int i=x; i<n; i++)
#define F0R(i,n) FOR(i,0,n)
#define ROF(i,x,n) for(int i=n-1; i>=x; i--)
#define R0F(i,n) ROF(i,0,n)
#define WTF cout << "WTF" << endl
#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int MAXN = 2e5 + 7;
const int ALPHA = 27;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 22;
int n, q;
int ns[MAXN], lazy[MAXN << 2];
PII tree[MAXN << 2];
inline PII operator + (const PII a, const PII b) {
return PII(min(a.F, b.F), max(a.S, b.S));
}
inline PII operator + (const PII a, const int b) {
return PII(a.F + b, a.S + b);
}
inline void shift(int now_on) {
tree[now_on << 1] = tree[now_on << 1] + lazy[now_on];
lazy[now_on << 1] += lazy[now_on];
tree[now_on << 1 | 1] = tree[now_on << 1 | 1] + lazy[now_on];
lazy[now_on << 1 | 1] += lazy[now_on];
lazy[now_on] = 0;
return;
}
PII build(int now_on = 1, int ls = 0, int rs = n - 1) {
if (ls == rs) return tree[now_on] = PII(ns[ls], ns[ls]);
int mid = (ls + rs) >> 1;
return tree[now_on] = build(now_on << 1, ls, mid) + build(now_on << 1 | 1, mid + 1, rs);
}
int lb(int lq, int now_on = 1, int ls = 0, int rs = n - 1) {
if (ls == rs) return ls;
int mid = (ls + rs) >> 1;
shift(now_on);
if (tree[now_on << 1].S >= lq) return lb(lq, now_on << 1, ls, mid);
return lb(lq, now_on << 1 | 1, mid + 1, rs);
}
int ub(int rq, int now_on = 1, int ls = 0, int rs = n - 1) {
if (ls == rs) return ls;
int mid = (ls + rs) >> 1;
shift(now_on);
if (tree[now_on << 1 | 1].F <= rq) return ub(rq, now_on << 1 | 1, mid + 1, rs);
return ub(rq, now_on << 1, ls, mid);
}
int get(int id, int now_on = 1, int ls = 0, int rs = n - 1) {
if (ls == rs) return tree[now_on].F;
int mid = (ls + rs) >> 1;
shift(now_on);
if (id <= mid) return get(id, now_on << 1, ls, mid);
return get(id, now_on << 1 | 1, mid + 1, rs);
}
void add(int lq, int rq, int val, int now_on = 1, int ls = 0, int rs = n - 1) {
if (rq < lq || rq < ls || rs < lq)
return;
if (lq <= ls && rs <= rq) {
tree[now_on] = tree[now_on] + val;
lazy[now_on] += val;
return;
}
int mid = (ls + rs) >> 1;
shift(now_on);
add(lq, rq, val, now_on << 1, ls, mid);
add(lq, rq, val, now_on << 1 | 1, mid + 1, rs);
tree[now_on] = tree[now_on << 1] + tree[now_on << 1 | 1];
return;
}
int main() {
IOS;
cin >> n >> q;
F0R(i, n) cin >> ns[i];
sort(ns, ns + n);
build();
while(q--) {
char tp; cin >> tp;
if (tp == 'F') {
int td, mnm; cin >> td >> mnm;
int st = lb(mnm);
int fn = min(n - 1, st + td - 1);
int md = get(fn);
int smd = lb(md), fmd = ub(md);
add(st, smd - 1, 1);
add(fmd - (td - ((smd - 1) - st + 1)) + 1, fmd, 1);
/*
F0R(i, n) cout << get(i) << ' ';
cout << endl;
*/
}
#define endl '\n'
else {
int mn, mx; cin >> mn >> mx;
cout << (mx < get(0) || mn > get(n - 1) ? 0 : ub(mx) - lb(mn) + 1) << endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
4932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
1696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
1732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
3148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
4748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
4676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
5440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
5152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
6004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |