제출 #1328017

#제출 시각아이디문제언어결과실행 시간메모리
1328017vtnooSnowball (JOI21_ho_t2)C++20
100 / 100
222 ms9972 KiB
#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define all(x) x.begin(), x.end()
#define sz(a) ((int) a.size())
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
const ll INF=2e18;
void chmin(ll &a,ll b){a=min(a,b);}
void chmax(ll &a,ll b){a=max(a,b);}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,q;cin>>n>>q;
	vector<ll>x(n+2,-INF);
	L(i,1,n)cin>>x[i];
	x.back()=INF;
	vector<ll>w(q);
	L(i,0,q-1){
		cin>>w[i];
	}
	vector<ll>pref(q+1);
	L(i,1,q){
		pref[i]+=w[i-1]+pref[i-1];
	}
	vector<ll>prefMin(q+1),prefMax(q+1);
	L(i,1,q){
		prefMin[i]=pref[i];
		chmin(prefMin[i],prefMin[i-1]);
	}
	L(i,1,q){
		prefMax[i]=pref[i];
		chmax(prefMax[i],prefMax[i-1]);
	}
	L(i,1,n){
		ll ans=0;
		int l=0,r=q+1;
		while(r-l>1){
			int m=(r+l)/2;
			if(x[i-1]+prefMax[m]<x[i]+prefMin[m]){
				l=m;
			}else r=m;
		}
		ll add=0;
		if(r!=q+1){
			add=max(0ll,(x[i]+prefMin[l])-(x[i-1]+prefMax[r]));
		}
		ans+=(x[i]-(x[i]+prefMin[l]))+add;
		l=0,r=q+1;
		while(r-l>1){
			int m=(r+l)/2;
			if(x[i+1]+prefMin[m]>x[i]+prefMax[m]){
				l=m;
			}else r=m;
		}
		add=0;
		if(r!=q+1){
			add=max(0ll,(x[i+1]+prefMin[r])-(x[i]+prefMax[l]));
		}
		ans+=((x[i]+prefMax[l])-x[i])+add;
		cout<<ans<<endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...