​​Orz大佬博客​​

CODE

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char cb[1<<18],*cs,*ct;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<18,stdin),cs==ct)?0:*cs++)
inline void rd(int &x) {
x = 0; char ch; while(!isdigit(ch=getc()));
do x=x*10+ch-'0'; while(isdigit(ch=getc()));
}
const int MAXN = 1000005;
int n, v[MAXN], ans[MAXN];
int main () {
rd(n);
for(int i = 1; i <= n; ++i) rd(v[i]), v[i]<<=1;

for(int i = 1; i <= n; ++i) if(v[i%n+1]>>1 > v[i]) ans[i] = i%n+1, v[i%n+1]>>=1;
for(int i=1;i<=n&&!ans[i];++i) if(v[i%n+1]>>1 > v[i]) ans[i] = i%n+1, v[i%n+1]>>=1;

for(int i = n; i >= 1; --i) if(v[i%n+1] > v[i] && ans[i%n+1]) ans[i] = i%n+1, v[i%n+1]>>=1;
for(int i = n; i >= 1; --i) if(v[i%n+1] > v[i] && ans[i%n+1]) ans[i] = i%n+1, v[i%n+1]>>=1;

for(int i = 1; i <= n; ++i) printf("%d%c", ans[i] ? ans[i] : i, " \n"[i==n]);
}