이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define inf 0x3f3f3f3f3f3f3f3f
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=70005,mod=1000000007;
#define num vector<int>
int n,a[maxn],val[maxn*4],minn[maxn*4],minid[maxn*4],tag[maxn*4],ans[maxn];
vector<int> res;
void pull(int k){
val[k]=val[k<<1]+val[k<<1|1];
if(!val[k<<1]) return minn[k]=minn[k<<1|1],minid[k]=minid[k<<1|1],void();
if(!val[k<<1|1]) return minn[k]=minn[k<<1],minid[k]=minid[k<<1],void();
minn[k]=min(minn[k<<1],minn[k<<1|1]);
if(minn[k]==minn[k<<1|1]) minid[k]=minid[k<<1|1];
else minid[k]=minid[k<<1];
}
void push(int k, int l, int r){
if(l!=r){
minn[k<<1]=minn[k<<1]+tag[k];
minn[k<<1|1]=minn[k<<1|1]+tag[k];
tag[k<<1]=tag[k<<1]+tag[k];
tag[k<<1|1]=tag[k<<1|1]+tag[k];
}
tag[k]=0;
}
void build(int k, int l, int r){
if(l==r){
minn[k]=a[l];
minid[k]=l;
val[k]=1;
return;
}
int mid=l+r>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
pull(k);
}
void modify(int k, int l, int r, int ql, int qr, int x){
if(l>qr||r<ql) return;
if(ql<=l&&qr>=r){
minn[k]+=x,tag[k]+=x;
return;
}
int mid=l+r>>1;
push(k,l,r);
modify(k<<1,l,mid,ql,qr,x),modify(k<<1|1,mid+1,r,ql,qr,x);
pull(k);
}
void modify2(int k, int l, int r, int p){
if(l==r){
val[k]--;
return;
}
int mid=l+r>>1;
push(k,l,r);
if(p<=mid) modify2(k<<1,l,mid,p);
else modify2(k<<1|1,mid+1,r,p);
pull(k);
}
pii query(int k, int l, int r, int ql, int qr){
if(l>qr||r<ql) return {inf,-1};
if(ql<=l&&qr>=r) return {minn[k],minid[k]};
push(k,l,r);
int mid=l+r>>1;
pii lres=query(k<<1,l,mid,ql,qr),rres=query(k<<1|1,mid+1,r,ql,qr);
if(rres.first<=lres.first) return rres;
return lres;
}
void print(int k, int l, int r){
bug(k,l,r,minn[k],minid[k]);
if(l==r) return;
push(k,l,r);
int mid=l+r>>1;
print(k<<1,l,mid),print(k<<1|1,mid+1,r);
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n;
rep(n) cin >> a[i];
rep3(i,n-1,1) a[i]=a[i]-a[i-1];
build(1,0,n-1);
//print(1,0,n-1);
rep(n){
int x=minid[1];
ans[x]=i+1;
bug(x);
modify2(1,0,n-1,x);
modify(1,0,n-1,x+1,n-1,-a[x]);
//print(1,0,n-1);
}
rep(n) cout << ans[i] << ' ';
cout << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
permutation.cpp: In function 'void build(long long int, long long int, long long int)':
permutation.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
57 | int mid=l+r>>1;
| ~^~
permutation.cpp: In function 'void modify(long long int, long long int, long long int, long long int, long long int, long long int)':
permutation.cpp:68:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int mid=l+r>>1;
| ~^~
permutation.cpp: In function 'void modify2(long long int, long long int, long long int, long long int)':
permutation.cpp:79:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int mid=l+r>>1;
| ~^~
permutation.cpp: In function 'std::pair<long long int, long long int> query(long long int, long long int, long long int, long long int, long long int)':
permutation.cpp:90:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
90 | int mid=l+r>>1;
| ~^~
permutation.cpp: In function 'void print(long long int, long long int, long long int)':
permutation.cpp:22:18: warning: statement has no effect [-Wunused-value]
22 | #define bug(...) 49
| ^~
permutation.cpp:97:5: note: in expansion of macro 'bug'
97 | bug(k,l,r,minn[k],minid[k]);
| ^~~
permutation.cpp:100:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
100 | int mid=l+r>>1;
| ~^~
permutation.cpp: In function 'int main()':
permutation.cpp:22:18: warning: statement has no effect [-Wunused-value]
22 | #define bug(...) 49
| ^~
permutation.cpp:114:9: note: in expansion of macro 'bug'
114 | bug(x);
| ^~~
# | 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... |