Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimzize("Ofast,no-stack-protector")
- #include<bits/stdc++.h>
- #define int long long
- #define quick ios::sync_with_stdio(0);cin.tie(0);
- #define rep(x,a,b) for(int x=a;x<=b;x++)
- #define repd(x,a,b) for(int x=a;x>=b;x--)
- #define lowbit(x) (x&-x)
- #define sz(x) (int)(x.size())
- #define F first
- #define S second
- #define all(x) x.begin(),x.end()
- #define mp make_pair
- #define eb emplace_back
- using namespace std;
- typedef complex<int> P;
- #define X real()
- #define Y imag()
- typedef pair<int,int> pii;
- void debug(){
- cout<<"\n";
- }
- template <class T,class ... U >
- void debug(T a, U ... b){
- cout<<a<<" ",debug(b...);
- }
- const int N=2e5+7;
- const int INF=1e18;
- int a[N];
- int pa[N];
- int ans[N];
- bool contain(int l,int r,int k){
- return l<=k&&k<=r;
- }
- signed main(){
- quick
- int n;
- cin>>n;
- rep(i,1,n){
- cin>>a[i];
- pa[i]=pa[i-1]+a[i];
- ans[i]=INF;
- }
- vector<tuple<int,int,int> > v;
- set<int> Lft;
- set<int> Rgt;
- rep(l,1,n){
- rep(r,l,n){
- v.eb(make_tuple(pa[r]-pa[l-1],l,r));
- }
- }
- sort(all(v));
- rep(k,1,n){
- rep(j,0,sz(v)-2){
- auto [a,b,c]=v[j];
- auto [a2,b2,c2]=v[j+1];
- if(contain(b,c,k)!=contain(b2,c2,k)){
- ans[k]=min(ans[k],a2-a);
- }
- }
- }
- rep(i,1,n) cout<<ans[i]<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement