Submission #1114169

#TimeUsernameProblemLanguageResultExecution timeMemory
1114169Dan4LifeSnowball (JOI21_ho_t2)C++17
100 / 100
105 ms18628 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) #define int long long const int N = (int)2e5+10; const int LINF = (int)1e18; int n, q, a[N], w[N], pr[N], mnpr[N], mxpr[N]; using ar2 = array<int,2>; ar2 xd[N]; ar2 f(int dis){ int a = 0, b = dis, mnB=dis, mxA = 0; int l = 0, r = q; while(l<r){ int mid = (l+r+1)/2; if(a+mxpr[mid] >= b+mnpr[mid]) r=mid-1; else l = mid; } mxA = a+mxpr[l], mnB = b+mnpr[l]; a += pr[l], b+=pr[l]; if(l<q){ a+=w[l]; b+=w[l]; if(a>mnB) a=mnB; if(b<mxA) b=mxA; mxA = max(mxA, a); mnB = min(mnB, b); } return {mxA,dis-mnB}; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> q; a[0] = -LINF; a[n+1]=LINF; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i < q; i++){ cin >> w[i],pr[i+1]=pr[i]+w[i]; mnpr[i+1]=min(mnpr[i],pr[i+1]); mxpr[i+1]=max(mxpr[i],pr[i+1]); } for(int i = 1; i <= n+1; i++) xd[i] = f(a[i]-a[i-1]); for(int i = 1; i <= n; i++) cout << xd[i][1]+xd[i+1][0] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...