/*input
5 9
1 3 2 5 2
F 2 1
F 3 2
C 3 6
C 2 9
F 2 3
C 6 8
F 2 1
F 2 2
C 3 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define REP(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define f first
#define s second
const int maxn=2e5+5;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long
pair<pii,int> query[maxn];
int ans[maxn],arr[maxn];
struct segt{
ll seg[4*maxn],lazy[4*maxn];
int n;
void resize(int _n){
n=_n;
}
void pushdown(int idx,int l,int r){
if(!lazy[idx]) return;
seg[idx]+=(r-l+1)*lazy[idx];
if(l==r){
lazy[idx]=0;
return;
}
lazy[idx*2]+=lazy[idx];
lazy[idx*2+1]+=lazy[idx];
lazy[idx]=0;
}
void mdf(int idx,int l,int r,int ql,int qr,int x){
pushdown(idx,l,r);
if(l>qr or r<ql) return;
if(ql<=l and r<=qr){
lazy[idx]+=x;
pushdown(idx,l,r);
return;
}
int mid=(l+r)/2;
mdf(idx*2,l,mid,ql,qr,x);
mdf(idx*2+1,mid+1,r,ql,qr,x);
seg[idx]=seg[idx*2]+seg[idx*2+1];
}
ll query(int idx,int l,int r,int ql,int qr){
if(l>qr or r<ql) return 0;
pushdown(idx,l,r);
if(ql<=l and r<=qr) return seg[idx];
int mid=(l+r)/2;
return query(idx*2,l,mid,ql,qr)+query(idx*2+1,mid+1,r,ql,qr);
}
ll query(int l,int r){
return query(1,0,n-1,l,r);
}
void mdf(int l,int r,int x){
if(l<0) l=0;
mdf(1,0,n-1,l,r,x);
}
int lb(int x){
int l=0,r=n-1;
while(l<r){
int mid=(l+r)/2;
if(query(mid,mid)>=x) r=mid;
else l=mid+1;
}
if(query(l,l)<x) return n;
return l;
}
int ub(int x){
int l=0,r=n-1;
while(l<r){
int mid=(l+r)/2;
if(query(mid,mid)>x) r=mid;
else l=mid+1;
}
if(query(l,l)<=x) return n;
return l;
}
}seg;
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,q;
cin>>n>>q;
vector<int> v;
REP(i,n){
int x;
cin>>x;
v.pb(x);
}
sort(ALL(v));
seg.resize(n);
REP(i,n) seg.mdf(i,i,v[i]);
//cout<<seg.ub(1);
while(q--){
char x;
int a,b;
cin>>x>>a>>b;
if(x=='F'){
int i=seg.lb(b);
if(i==n) continue;
if(i+a>=n){
seg.mdf(i,n-1,1);
continue;
}
int z=seg.query(min(i+a-1,n-1),min(i+a-1,n-1));
int l=seg.lb(z),r=seg.ub(z)-1;
int cnt=a-(l-i);
seg.mdf(r-cnt+1,r,1);
seg.mdf(i,l-1,1);
//REP(i,n) cout<<seg.query(i,i)<<' ';
//cout<<'\n';
}
else{
cout<<seg.ub(b)-seg.lb(a)<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
457 ms |
6284 KB |
Output is correct |
2 |
Correct |
691 ms |
6728 KB |
Output is correct |
3 |
Correct |
255 ms |
6536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
460 KB |
Output is correct |
3 |
Correct |
9 ms |
460 KB |
Output is correct |
4 |
Correct |
6 ms |
332 KB |
Output is correct |
5 |
Correct |
253 ms |
1692 KB |
Output is correct |
6 |
Correct |
313 ms |
1880 KB |
Output is correct |
7 |
Correct |
22 ms |
732 KB |
Output is correct |
8 |
Correct |
184 ms |
1348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
286 ms |
2064 KB |
Output is correct |
2 |
Correct |
334 ms |
2108 KB |
Output is correct |
3 |
Correct |
6 ms |
588 KB |
Output is correct |
4 |
Correct |
223 ms |
1572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
2084 KB |
Output is correct |
2 |
Correct |
334 ms |
1988 KB |
Output is correct |
3 |
Correct |
40 ms |
764 KB |
Output is correct |
4 |
Correct |
302 ms |
2116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
3936 KB |
Output is correct |
2 |
Correct |
616 ms |
6268 KB |
Output is correct |
3 |
Correct |
99 ms |
1988 KB |
Output is correct |
4 |
Correct |
215 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
5984 KB |
Output is correct |
2 |
Correct |
623 ms |
6484 KB |
Output is correct |
3 |
Correct |
262 ms |
6488 KB |
Output is correct |
4 |
Correct |
85 ms |
1908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
489 ms |
6184 KB |
Output is correct |
2 |
Correct |
477 ms |
6188 KB |
Output is correct |
3 |
Correct |
263 ms |
6468 KB |
Output is correct |
4 |
Correct |
83 ms |
1892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
659 ms |
6612 KB |
Output is correct |
2 |
Correct |
628 ms |
6464 KB |
Output is correct |
3 |
Correct |
132 ms |
5664 KB |
Output is correct |
4 |
Correct |
521 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
6456 KB |
Output is correct |
2 |
Correct |
623 ms |
6584 KB |
Output is correct |
3 |
Correct |
862 ms |
6848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
7320 KB |
Output is correct |