Submission #925419

#TimeUsernameProblemLanguageResultExecution timeMemory
925419XiaoyangSnowball (JOI21_ho_t2)C++17
100 / 100
858 ms12512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 1ll<<60 #define rep(i,a,b) for (ll i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define mod 1000000007 #define ALL(x) x.begin(),x.end() #define endl "\n" void inc(ll &a,ll b) {a=(a+b)%mod;} void dec(ll &a,ll b) {a=(a-b+mod)%mod;} int prod(ll a,ll b) {return ll(a)*ll(b)%mod;} int lowbit(ll x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} const ll maxn=222222; ll a[maxn],pos[maxn],neg[maxn]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); ll n,q;cin>>n>>q; rep(i,1,n+1)cin>>a[i]; a[n+1]=inf; ll curr=0,mx=0,mn=0; rep(i,1,q+1){ ll x;cin>>x; curr+=x; mx=max(mx,curr); mn=min(mn,curr); pos[i]=mx; neg[i]=-mn; } ll prev=a[1]+mn; rep(i,1,n+1){ ll L=max(prev,a[i]+mn); ll lo=a[i],hi=a[i+1]; while(lo<hi){ ll mid=(lo+hi+1)>>1; ll tmp=lower_bound(pos+1,pos+q+1,mid-a[i])-pos; ll tmpp=lower_bound(neg+1,neg+q+1,a[i+1]-mid+1)-neg; if(tmp<tmpp)lo=mid; else hi=mid-1; } //bsta for last point before overlap cout<<lo-L<<endl; prev=hi; } return 0; } /* 4 3 -2 3 5 8 2 -4 7 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...