Submission #1110853

# Submission time Handle Problem Language Result Execution time Memory
1110853 2024-11-10T16:00:33 Z imarn Snowball (JOI21_ho_t2) C++14
0 / 100
1 ms 336 KB
#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 x[n+1];for(int i=1;i<=n;i++)cin>>x[i];
    vector<pll> w(q+1),ww(q+1);w[0]={0,0},ww[0]={0,0};for(int i=1;i<=q;i++)cin>>w[i].f,w[i].f+=w[i-1].f,w[i].s=i,ww[i]={-w[i].f,w[i].s};
    ll t=2e16,t2=2e16;
    ll l[n+1],r[n+1];
    for(int i=1;i<=n;i++){
        w[i]=max(w[i],w[i-1]);
        ww[i]=max(ww[i-1],ww[i]);
    }
    for(int i=q;i>=0;i--){
        t=min(t,w[i].s);
        w[i].s=min(t,w[i].s);
        t2=min(t2,ww[i].s);
        ww[i].s=min(t2,ww[i].s);
    }
    for(int i=2;i<=n;i++){
        if(r[i-1]<=l[i])continue;
        ll tl=l[i],tr=r[i-1]+1;
        while(tl<tr){
            ll md=(tl+tr)>>1;ll lf,rg;
            lf = lower_bound(all(w),make_pair(md-x[i-1],-1ll))->s;
            rg=lower_bound(all(ww),make_pair(x[i]-md+1,-1ll))->s;
            if(lf<rg)tl=md+1;
            else tr=md;
        }r[i-1]=tl-1;
        l[i]=tl-1;
    }
    for(int i=1;i<=n;i++){
        cout<<r[i]-l[i]<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -