Submission #534838

# Submission time Handle Problem Language Result Execution time Memory
534838 2022-03-09T03:37:30 Z Paul_Liao_1457 Snowball (JOI21_ho_t2) C++14
100 / 100
392 ms 17928 KB
// 還要更強
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stack>
#include<string.h>
#include<random>
#include<algorithm>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define INF (ll)(3e18)
#define pb push_back
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int n,q;
vector<ll> v,Q,p1,p2,s1,s2;
vector<pair<ll,pair<ll,ll> > >  ya1,ya2;

ll ans[200005];

signed main(){
    AC;
    cin>>n>>q;
    v.pb(-INF);
    FOR(i,0,n){
        ll x; cin>>x;
        v.pb(x);
    }
    v.pb(INF);
    FOR(i,0,q){
        ll y; cin>>y;
        Q.pb(y);
    }
    ll now=0,maxn=0,minn=0;
    FOR(j,0,q){
        now+=Q[j]; maxn=max(maxn,now); minn=min(minn,now);
        if(now<0) ya1.pb({maxn-now,{-now,maxn}});
        if(now>0) ya2.pb({now-minn,{now,-minn}});
    }
    sort(ya1.begin(),ya1.end());
    sort(ya2.begin(),ya2.end());
    maxn=0;
    for(auto i:ya1){
        maxn=max(maxn,i.S.F);
        p1.pb(maxn);
    }
    maxn=0;
    for(auto i:ya2){
        maxn=max(maxn,i.S.F);
        p2.pb(maxn);
    }
    minn=INF;
    for(int i=(int)ya1.size()-1;i>=0;i--){
        minn=min(minn,ya1[i].S.S);
        s1.pb(minn);
    }
    minn=INF;
    for(int i=(int)ya2.size()-1;i>=0;i--){
        minn=min(minn,ya2[i].S.S);
        s2.pb(minn);
    }
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    
    FOR(i,1,n+1){
        ll l=0,r=(int)ya1.size();
        ll len1=v[i]-v[i-1],len2=v[i+1]-v[i],maxn=-1;
        while(l<r){
            ll mid=(l+r)>>1;
            if(ya1[mid].F<=len1){
                maxn=max(maxn,mid); l=mid+1;
            }
            else{
                r=mid;
            }
        }
        ll pos=v[i];
        if(maxn!=-1) pos=min(pos,v[i]-p1[maxn]);
        if(maxn+1<s1.size()) pos=min(pos,v[i-1]+s1[maxn+1]);
        ans[i]+=v[i]-pos;
        l=0; r=(int)ya2.size(); maxn=-1;
        while(l<r){
            ll mid=(l+r)>>1;
            if(ya2[mid].F<=len2){
                maxn=max(maxn,mid); l=mid+1;
            }
            else{
                r=mid;
            }
        }
        pos=v[i];
        if(maxn!=-1) pos=max(pos,v[i]+p2[maxn]);
        if(maxn+1<s2.size()) pos=max(pos,v[i+1]-s2[maxn+1]);
        ans[i]+=pos-v[i];
    }
    FOR(i,1,n+1) cout<<ans[i]<<endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:90:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         if(maxn+1<s1.size()) pos=min(pos,v[i-1]+s1[maxn+1]);
      |            ~~~~~~^~~~~~~~~~
Main.cpp:104:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         if(maxn+1<s2.size()) pos=max(pos,v[i+1]-s2[maxn+1]);
      |            ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 5 ms 464 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 500 KB Output is correct
9 Correct 4 ms 464 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 5 ms 464 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 500 KB Output is correct
9 Correct 4 ms 464 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 37 ms 11344 KB Output is correct
21 Correct 35 ms 11032 KB Output is correct
22 Correct 39 ms 11284 KB Output is correct
23 Correct 34 ms 11404 KB Output is correct
24 Correct 67 ms 11836 KB Output is correct
25 Correct 378 ms 15592 KB Output is correct
26 Correct 383 ms 15672 KB Output is correct
27 Correct 353 ms 15388 KB Output is correct
28 Correct 346 ms 15720 KB Output is correct
29 Correct 368 ms 15264 KB Output is correct
30 Correct 350 ms 15152 KB Output is correct
31 Correct 287 ms 13212 KB Output is correct
32 Correct 289 ms 8308 KB Output is correct
33 Correct 34 ms 2016 KB Output is correct
34 Correct 378 ms 15656 KB Output is correct
35 Correct 362 ms 15424 KB Output is correct
36 Correct 392 ms 15876 KB Output is correct
37 Correct 368 ms 15696 KB Output is correct
38 Correct 377 ms 15420 KB Output is correct
39 Correct 378 ms 15660 KB Output is correct
40 Correct 311 ms 15748 KB Output is correct
41 Correct 39 ms 11928 KB Output is correct
42 Correct 272 ms 5764 KB Output is correct
43 Correct 312 ms 15940 KB Output is correct
44 Correct 38 ms 11164 KB Output is correct
45 Correct 309 ms 15708 KB Output is correct
46 Correct 300 ms 16032 KB Output is correct
47 Correct 316 ms 17928 KB Output is correct
48 Correct 309 ms 16812 KB Output is correct