This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
if(i<=n){
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |