//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,q;
int arr[100005];
struct node{
int s,e,m;
int val=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,int j,int k){
if (s==i && e==j) val+=k;
else if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
}
int query(int i){
if (s==e) return val;
else if (i<=m) return val+l->query(i);
else return val+r->query(i);
}
} *root=new node(0,100005);
int find(int val){
int lo=-1,hi=n,mi;
while (hi-lo>1){
mi=lo+hi>>1;
if (root->query(mi)<=val) lo=mi;
else hi=mi;
}
return lo;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>q;
rep(x,0,n) cin>>arr[x];
sort(arr,arr+n);
rep(x,0,n) root->update(x,x,arr[x]);
char c;
int a,b;
while (q--){
cin>>c;
if (c=='F'){
cin>>a>>b;
int l=find(b-1)+1;
if (l+a>=n){
root->update(l,n-1,1);
}
else{
int r=l+a-1;
int l2=find(root->query(r)-1)+1;
int r2=find(root->query(r));
if (l!=l2) root->update(l,l2-1,1);
//cerr<<l<<" "<<r<<endl;
//cerr<<l2<<" "<<r2<<endl;
//cerr<<l2+r2-r<<" "<<r2<<endl;
root->update(l2+r2-r,r2,1);
}
//rep(x,0,n) cout<<root->query(x)<<" "; cout<<endl;
}
else{
cin>>a>>b;
cout<<find(b)-find(a-1)<<endl;
}
}
}
Compilation message
grow.cpp: In constructor 'node::node(int, int)':
grow.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | s=_s,e=_e,m=s+e>>1;
| ~^~
grow.cpp: In function 'int find(int)':
grow.cpp:62:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | mi=lo+hi>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
20844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
9708 KB |
Output is correct |
2 |
Correct |
19 ms |
9836 KB |
Output is correct |
3 |
Correct |
18 ms |
9836 KB |
Output is correct |
4 |
Correct |
16 ms |
9836 KB |
Output is correct |
5 |
Correct |
182 ms |
10860 KB |
Output is correct |
6 |
Runtime error |
29 ms |
19692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
51 ms |
19948 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
19692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
91 ms |
20588 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
64 ms |
20716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
40 ms |
20460 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
11948 KB |
Output is correct |
2 |
Runtime error |
65 ms |
20588 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
75 ms |
20844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
12524 KB |
Output is correct |