#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, m, x, y;
char t;
vector<int> v;
struct segtree
{
int d[4*nx], lz[4*nx];
void pushlz(int l, int r, int i)
{
if (l==r) return d[i]+=lz[i], lz[i]=0, void();
lz[2*i]+=lz[i];
lz[2*i+1]+=lz[i];
d[i]+=lz[i];
lz[i]=0;
}
void build(int l, int r, int i)
{
if (l==r) return void(d[i]=v[l-1]);
int md=(l+r)/2;
build(l, md, 2*i);
build(md+1, r, 2*i+1);
d[i]=d[2*i+1];
}
void update(int l, int r, int i, int ul, int ur)
{
pushlz(l, r, i);
if (r<ul||ur<l) return;
if (ul<=l&&r<=ur) return lz[i]++, pushlz(l, r, i), void();
int md=(l+r)/2;
update(l, md, 2*i, ul, ur);
update(md+1, r, 2*i+1, ul, ur);
d[i]=d[2*i+1];
}
int query(int l, int r, int i, int idx)
{
pushlz(l, r, i);
if (l==r) return d[i];
int md=(l+r)/2;
if (idx<=md) return query(l, md, 2*i, idx);
return query(md+1, r, 2*i+1, idx);
}
int lower_bound(int l, int r, int i, int vl)
{
pushlz(l, r, i);
if (l==r) return l;
int md=(l+r)/2;
pushlz(l, md ,2*i);
pushlz(md+1, r, 2*i+1);
if (d[2*i]>=vl) return lower_bound(l, md ,2*i, vl);
else return lower_bound(md+1, r, 2*i+1, vl);
}
void show()
{
for (int i=1; i<=n+1; i++) cout<<query(1, n+1, 1, i)<<' ';
cout<<'\n';
}
} s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
v.resize(n+1);
for (int i=0; i<n; i++) cin>>v[i];
v[n]=2e9;
sort(v.begin(), v.end());
s.build(1, n+1, 1);
//s.show();
for (int i=0; i<m; i++)
{
cin>>t>>x>>y;
if (t=='F')
{
swap(x, y);
int st=s.lower_bound(1, n+1, 1, x), lst=st+y-1;
//cout<<"here"<<' '<<st<<' '<<lst<<'\n';
if (lst>=n) s.update(1, n+1, 1, st, n);
else
{
int lvl=s.query(1, n+1, 1, lst), pv=s.lower_bound(1, n+1, 1, lvl)-1, sv=s.lower_bound(1, n+1, 1, lvl+1)-1;
int nd=lst-pv;
if (nd>=y) s.update(1, n+1, 1, sv-nd+1, sv);
else s.update(1, n+1, 1, sv-nd+1, sv), s.update(1, n+1, 1, st, st+y-nd-1);
}
//s.show();
}
else
{
//cout<<"query"<<' '<<s.lower_bound(1, n+1, 1, y+1)<<' '<<s.lower_bound(1, n+1, 1, x)<<'\n';
cout<<(s.lower_bound(1, n+1, 1, y+1)-s.lower_bound(1, n+1, 1, x))<<'\n';
}
}
}
/*
5 1
1 3 2 5 2
F 2 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3416 KB |
Output is correct |
2 |
Correct |
84 ms |
3496 KB |
Output is correct |
3 |
Correct |
49 ms |
3364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
34 ms |
716 KB |
Output is correct |
6 |
Correct |
41 ms |
884 KB |
Output is correct |
7 |
Correct |
4 ms |
604 KB |
Output is correct |
8 |
Correct |
24 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
744 KB |
Output is correct |
2 |
Correct |
40 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
31 ms |
772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
860 KB |
Output is correct |
2 |
Correct |
42 ms |
852 KB |
Output is correct |
3 |
Correct |
7 ms |
604 KB |
Output is correct |
4 |
Correct |
39 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
2908 KB |
Output is correct |
2 |
Correct |
78 ms |
3420 KB |
Output is correct |
3 |
Correct |
13 ms |
2652 KB |
Output is correct |
4 |
Correct |
40 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
3408 KB |
Output is correct |
2 |
Correct |
76 ms |
3420 KB |
Output is correct |
3 |
Correct |
48 ms |
3160 KB |
Output is correct |
4 |
Correct |
11 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
4192 KB |
Output is correct |
2 |
Correct |
56 ms |
3416 KB |
Output is correct |
3 |
Correct |
51 ms |
3164 KB |
Output is correct |
4 |
Correct |
11 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
3484 KB |
Output is correct |
2 |
Correct |
80 ms |
3468 KB |
Output is correct |
3 |
Correct |
21 ms |
3420 KB |
Output is correct |
4 |
Correct |
57 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
3416 KB |
Output is correct |
2 |
Correct |
79 ms |
3428 KB |
Output is correct |
3 |
Correct |
118 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
3924 KB |
Output is correct |