Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<queue>
- #include<algorithm>
- #include<vector>
- #define FOR(x,y,z) for(int x=y;x<z;(x)++)
- #define FORD(x,y,z) for(int x=y;x>=z;(x)--)
- #define PB push_back
- #define F first
- #define S second
- #define MP make_pair
- using namespace std;
- int N,T[500010],WL[500010],WR[500010];
- vector<pair<int,int> > Q[500010];
- int main()
- {
- scanf("%d",&N);
- FOR(i,0,N)scanf("%d",&T[i]);
- int curr=0,last=0;;
- FOR(i,0,N)
- {
- if(curr<=T[i])curr=T[i];
- if(T[i]>last && i<=N-2){Q[i+1].PB(MP(0,i));last=T[i];}
- FOR(j,0,Q[i].size())
- {
- int a=Q[i][j].F,b=Q[i][j].S;
- if(curr<T[b]+a+1)curr=T[b]+a+1;
- if(b+(a+1)*(a+1)+1<=N-1)Q[b+(a+1)*(a+1)+1].PB(MP(a+1,b));
- }
- Q[i].clear();
- WL[i]=curr;
- }
- curr=0,last=0;
- FORD(i,N-1,0)
- {
- if(curr<=T[i])curr=T[i];
- if(T[i]>last && i>=1){Q[i-1].PB(MP(0,i));last=T[i];}
- FOR(j,0,Q[i].size())
- {
- int a=Q[i][j].F,b=Q[i][j].S;
- if(curr<T[b]+a+1)curr=T[b]+a+1;
- if(b-(a+1)*(a+1)-1>=0)Q[b-(a+1)*(a+1)-1].PB(MP(a+1,b));
- }
- Q[i].clear();
- WR[i]=curr;
- }
- // FOR(i,0,N)printf("%d ",WL[i]);
- FOR(i,0,N)printf("%d\n",max(WR[i],WL[i])-T[i]);
- // system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement