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 <bits/stdc++.h>
using namespace std;
const int MAX = 1e5+5;
int N,M,A[MAX],T[4*MAX];
void upt(int l, int r, int st, int en, int pos, int val){
if(en<l || st>r) return;
if(l<=st && en<=r){
T[pos] += val;
return;
}
upt(l,r,st,(st+en)/2,pos*2,val);
upt(l,r,(st+en)/2+1,en,pos*2+1,val);
}
int get(int x, int st, int en, int pos){
if(en<x || st>x) return 0;
if(st==en) return T[pos];
return T[pos]+get(x,st,(st+en)/2,2*pos)+get(x,(st+en)/2+1,en,2*pos+1);
}
int sear(int h, int st, int en){
if(st==en) return st;
if(get((st+en)/2,1,N,1)>=h) return sear(h,st,(st+en)/2);
else return sear(h,(st+en)/2+1,en);
}
int main()
{
cin >> N >> M;
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,1,N,1,A[i]);
for(int i=0; i<M; i++){
char O;
int x,y;
cin >> O >> x >> y;
if(O=='F'){
int a = sear(y,1,N+1);
if(a+x-1>N) upt(a,N,1,N,1,1);
else{
int h = get(a+x-1,1,N,1);
int b = sear(h,1,N+1);
upt(a,b-1,1,N,1,1);
int d = sear(h+1,1,N+1);
upt(d-a-x+b,d-1,1,N,1,1);
}
}
if(O=='C'){
cout << sear(y+1,1,N+1)-sear(x,1,N+1) << '\n';
}
}
}
# | 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... |