제출 #1110863

#제출 시각아이디문제언어결과실행 시간메모리
1110863imarnSnowball (JOI21_ho_t2)C++14
100 / 100
103 ms13808 KiB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
bool cmp(pll a,pll b){
    if(a.f==b.f)return a.s>b.s;
    else return a.f<b.f;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,q;cin>>n>>q;ll ans[n+1]={0};
    ll x[n+1];for(int i=1;i<=n;i++)cin>>x[i];
    vector<ll> w(q+1),ww(q+1);w[0]=0,ww[0]=0;for(int i=1;i<=q;i++)cin>>w[i],w[i]+=w[i-1],ww[i]=-w[i];
    for(int i=1;i<=q;i++){
        w[i]=max(w[i],w[i-1]);
        ww[i]=max(ww[i],ww[i-1]);
    }
    for(int i=2;i<=n;i++){
        int l=1,r=q+1;
        while(l<r){
            int m=(l+r)>>1;
            if(x[i-1]+w[m]>x[i]-ww[m])r=m;
            else l=m+1;
        }
        if(r==q+1)ans[i-1]+=w[q],ans[i]+=ww[q];
        else {
            ans[i-1]+=w[l-1];
            ans[i]+=ww[l-1];
            if(w[l-1]!=w[l]){
                ans[i-1]+=(x[i]-ww[l-1])-(x[i-1]+w[l-1]);
            }
            else {
                ans[i]+=(x[i]-ww[l-1])-(x[i-1]+w[l-1]);
            }
        }
    }ans[1]+=ww[q],ans[n]+=w[q];
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...