이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#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){
if (l<=n-1) 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;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
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;
| ~~^~~
# | 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... |