Submission #1039314

# Submission time Handle Problem Language Result Execution time Memory
1039314 2024-07-30T17:11:31 Z DucNguyen2007 Snowball (JOI21_ho_t2) C++14
100 / 100
87 ms 20048 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 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 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 2 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 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 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 2 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 18 ms 8792 KB Output is correct
21 Correct 17 ms 8600 KB Output is correct
22 Correct 16 ms 8328 KB Output is correct
23 Correct 15 ms 8192 KB Output is correct
24 Correct 20 ms 9036 KB Output is correct
25 Correct 72 ms 18136 KB Output is correct
26 Correct 75 ms 17996 KB Output is correct
27 Correct 73 ms 17820 KB Output is correct
28 Correct 75 ms 17864 KB Output is correct
29 Correct 87 ms 17496 KB Output is correct
30 Correct 63 ms 16720 KB Output is correct
31 Correct 42 ms 16212 KB Output is correct
32 Correct 39 ms 16468 KB Output is correct
33 Correct 7 ms 2136 KB Output is correct
34 Correct 86 ms 18424 KB Output is correct
35 Correct 73 ms 18008 KB Output is correct
36 Correct 79 ms 18260 KB Output is correct
37 Correct 83 ms 17940 KB Output is correct
38 Correct 71 ms 17744 KB Output is correct
39 Correct 65 ms 17836 KB Output is correct
40 Correct 46 ms 17912 KB Output is correct
41 Correct 22 ms 9308 KB Output is correct
42 Correct 45 ms 16468 KB Output is correct
43 Correct 51 ms 19932 KB Output is correct
44 Correct 18 ms 9300 KB Output is correct
45 Correct 52 ms 17996 KB Output is correct
46 Correct 49 ms 19796 KB Output is correct
47 Correct 50 ms 20048 KB Output is correct
48 Correct 58 ms 20004 KB Output is correct