Submission #1039315

# Submission time Handle Problem Language Result Execution time Memory
1039315 2024-07-30T17:11:52 Z vjudge1 Snowball (JOI21_ho_t2) C++17
100 / 100
80 ms 14672 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,q;
pll b[maxN+1];
ll x[maxN+1],a[maxN+1],w[maxN+1],pre1[maxN+1],pre2[maxN+1],sum[maxN+1];
bool check(int k,ll tmp)
{
    return ((pre1[k]+pre2[k])<=tmp);
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for(int i=1;i<=q;i++)
    {
        cin>>w[i];
    }
    sum[0]=0;
    pre1[0]=pre2[0]=0;
    for(int j=1;j<=q;j++)
    {
        sum[j]=sum[j-1]+w[j];
        pre1[j]=max(pre1[j-1],sum[j]);
        pre2[j]=max(pre2[j-1],-sum[j]);
    }
    a[1]=pre2[q];
    a[n]=pre1[q];
    for(int i=1;i<n;i++)
    {
        ll tmp=x[i+1]-x[i];
        int l=1,r=q,res=0;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(check(mid,tmp))
            {
                res=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        if(res>0)
        {
            b[i].fi=pre1[res];
            b[i].se=pre2[res];
        }
        if(res<q)
        {
            ll pre_l=b[i].fi,pre_r=b[i].se;
            ll cur=tmp-pre_l-pre_r;
            if(sum[res+1]>0)
            {
                b[i].fi+=cur;
            }
            else b[i].se+=cur;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i<n)
        {
            a[i]+=b[i].fi;
            a[i+1]+=b[i].se;
        }
        cout<<a[i]<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 22 ms 6492 KB Output is correct
21 Correct 16 ms 6492 KB Output is correct
22 Correct 15 ms 6744 KB Output is correct
23 Correct 15 ms 6744 KB Output is correct
24 Correct 20 ms 7516 KB Output is correct
25 Correct 74 ms 14532 KB Output is correct
26 Correct 70 ms 14428 KB Output is correct
27 Correct 72 ms 14364 KB Output is correct
28 Correct 72 ms 14160 KB Output is correct
29 Correct 80 ms 14164 KB Output is correct
30 Correct 62 ms 13560 KB Output is correct
31 Correct 41 ms 13316 KB Output is correct
32 Correct 38 ms 13136 KB Output is correct
33 Correct 8 ms 1884 KB Output is correct
34 Correct 72 ms 14320 KB Output is correct
35 Correct 66 ms 14164 KB Output is correct
36 Correct 65 ms 14328 KB Output is correct
37 Correct 70 ms 14156 KB Output is correct
38 Correct 68 ms 14160 KB Output is correct
39 Correct 64 ms 14160 KB Output is correct
40 Correct 43 ms 14260 KB Output is correct
41 Correct 16 ms 6492 KB Output is correct
42 Correct 34 ms 13164 KB Output is correct
43 Correct 54 ms 14532 KB Output is correct
44 Correct 15 ms 6492 KB Output is correct
45 Correct 41 ms 14172 KB Output is correct
46 Correct 43 ms 14672 KB Output is correct
47 Correct 46 ms 14672 KB Output is correct
48 Correct 44 ms 14420 KB Output is correct