#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
//#define ordered_set tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>
int n,q;
const int mxN=1e5+1;
vector<int> tree(4*mxN);
int cal(int node, int L, int R, int l, int r){
if(L>r||R<l) return 0;
if(L>=l&&R<=r) return tree[node];
return tree[node]+cal(node*2,L,(L+R)/2,l,r)+cal(node*2+1,(L+R)/2+1,R,l,r);
}
int caln(int x){
int l=1,r=n;
while(l<=r){
int m=l+(r-l)/2;
if(cal(1,1,n,m,m)>=x) r=m-1;
else l=m+1;
}
return l;
}
int calx(int x){
int l=1,r=n;
while(l<=r){
int m=l+(r-l)/2;
if(cal(1,1,n,m,m)>x) r=m-1;
else l=m+1;
}
return l;
}
void up(int node, int L, int R, int l, int r, int v){
if(L>r||R<l) return;
if(L>=l&&R<=r){
tree[node]+=v;
return;
}
up(node*2,L,(L+R)/2,l,r,v);
up(node*2+1,(L+R)/2+1,R,l,r,v);
}
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
vector<int> a(n+1);
for(int i=1; i<=n; i++) cin>>a[i];
sort(a.begin(),a.end());
for(int i=1; i<=n; i++) up(1,1,n,i,i,a[i]);
while(q--){
char c; cin>>c;
int u,v; cin>>u>>v;
if(c=='F'){
int i=caln(v);
int p=min(i+u-1,n);
int l=caln(cal(1,1,n,p,p));
int r=calx(cal(1,1,n,p,p));
int need=p-l+1;
up(1,1,n,i,l-1,1);
up(1,1,n,r-need,r-1,1);
}else{
cout<<calx(v)-caln(u)<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
258 ms |
5312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3420 KB |
Output is correct |
2 |
Correct |
6 ms |
3420 KB |
Output is correct |
3 |
Correct |
7 ms |
3620 KB |
Output is correct |
4 |
Correct |
4 ms |
3416 KB |
Output is correct |
5 |
Correct |
182 ms |
4660 KB |
Output is correct |
6 |
Incorrect |
202 ms |
4688 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
190 ms |
4740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
161 ms |
5328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
262 ms |
5152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
370 ms |
5200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
281 ms |
5140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
6016 KB |
Output is correct |
2 |
Incorrect |
415 ms |
5456 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
345 ms |
5712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
6548 KB |
Output is correct |