#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;
int n, q;
struct node {
int mx, lz;
} tree[4*MX];
int A[MX];
void busy(int v, int s, int e){
int &z=tree[v].lz;
if(s!=e){
node &nd1=tree[v*2], &nd2=tree[v*2+1];
nd1.lz+=z, nd2.lz+=z;
nd1.mx+=z, nd2.mx+=z;
}
z=0;
}
void upt(int v, int s, int e, int l, int r, int val){
if(e<l || r<s) return;
node &nd=tree[v];
if(l<=s && e<=r){
nd.lz+=val;
nd.mx+=val;
return;
}
busy(v,s,e);
upt(v*2,s,(s+e)/2,l,r,val);
upt(v*2+1,(s+e)/2+1,e,l,r,val);
nd.mx=max(tree[v*2].mx, tree[v*2+1].mx);
}
void upt(int l, int r, int val){
if(r<l) return;
upt(1,1,n,l,r,val);
}
int lb(int v, int s, int e, int h){
busy(v,s,e);
if(s==e) return s;
if(tree[v*2].mx>=h) return lb(v*2,s,(s+e)/2,h);
else return lb(v*2+1,(s+e)/2+1,e,h);
}
int lb(int h){
if(tree[1].mx<h) return n+1;
return lb(1,1,n,h);
}
int val(int v, int s, int e, int pos){
if(pos<s || e<pos) return 0;
busy(v,s,e);
if(s==e) return tree[v].mx;
return val(v*2,s,(s+e)/2,pos) + val(v*2+1,(s+e)/2+1,e,pos);
}
int val(int pos){
return val(1,1,n,pos);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>A[i];
}
sort(A+1, A+n+1);
for(int i=1; i<=n; i++){
upt(i, i, A[i]);
}
for(int i=1; i<=q; i++){
char o; int x, y; cin>>o>>x>>y;
// for(int i=1; i<=n; i++) cout<<val(i)<<' ';
// cout<<'\n';
if(o=='F'){
int l=lb(y); // l부터 x개
if(l==n+1) continue;
x=min(x, n-l+1);
int v=val(l+x-1);
int a=lb(v)-1;
upt(l,a,1); x-=(a-l+1);
int r=lb(v+1)-1;
upt(r-x+1,r,1);
}
else{
int l=lb(x), r=lb(y+1);
cout<<r-l<<'\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
2936 KB |
Output is correct |
2 |
Correct |
196 ms |
3132 KB |
Output is correct |
3 |
Correct |
168 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3132 KB |
Output is correct |
2 |
Correct |
6 ms |
3132 KB |
Output is correct |
3 |
Correct |
7 ms |
3132 KB |
Output is correct |
4 |
Correct |
3 ms |
3132 KB |
Output is correct |
5 |
Correct |
60 ms |
3132 KB |
Output is correct |
6 |
Correct |
64 ms |
3132 KB |
Output is correct |
7 |
Correct |
8 ms |
3132 KB |
Output is correct |
8 |
Correct |
38 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
3132 KB |
Output is correct |
2 |
Correct |
65 ms |
3132 KB |
Output is correct |
3 |
Correct |
5 ms |
3132 KB |
Output is correct |
4 |
Correct |
51 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
3132 KB |
Output is correct |
2 |
Correct |
85 ms |
3132 KB |
Output is correct |
3 |
Correct |
22 ms |
3132 KB |
Output is correct |
4 |
Correct |
72 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
3132 KB |
Output is correct |
2 |
Correct |
157 ms |
3256 KB |
Output is correct |
3 |
Correct |
25 ms |
3256 KB |
Output is correct |
4 |
Correct |
204 ms |
3256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
3256 KB |
Output is correct |
2 |
Correct |
174 ms |
3260 KB |
Output is correct |
3 |
Correct |
169 ms |
3260 KB |
Output is correct |
4 |
Correct |
27 ms |
3260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
3260 KB |
Output is correct |
2 |
Correct |
127 ms |
3360 KB |
Output is correct |
3 |
Correct |
171 ms |
3360 KB |
Output is correct |
4 |
Correct |
22 ms |
3360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
214 ms |
3360 KB |
Output is correct |
2 |
Correct |
152 ms |
3360 KB |
Output is correct |
3 |
Correct |
78 ms |
3360 KB |
Output is correct |
4 |
Correct |
127 ms |
3360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
3360 KB |
Output is correct |
2 |
Correct |
185 ms |
3360 KB |
Output is correct |
3 |
Correct |
226 ms |
3360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
3644 KB |
Output is correct |