Submission #523332

# Submission time Handle Problem Language Result Execution time Memory
523332 2022-02-07T13:09:19 Z lucri Snowball (JOI21_ho_t2) C++17
100 / 100
228 ms 11820 KB
#include <iostream>
#include <cmath>
using namespace std;
long long n,q,x[200010],ans[200010],mp[200010],w,cnt,dmin,dmax;
long long cb(long long b,long long e,long long val)
{
    while(b<=e)
    {
        long long m=(b+e)/2;
        if(mp[m-1]-mp[m]<val&&mp[m]-mp[m-1]<val)
            b=m+1;
        else
            e=m-1;
    }
    return b;
}
int main()
{
    cin>>n>>q;
    for(long long i=1;i<=n;++i)
    {
        cin>>x[i];
    }
    long long dp=0;
    for(long long i=1;i<=q;++i)
    {
        cin>>w;
        dp+=w;
        if(dp<0)
        {
            if(mp[cnt]<0)
            {
                if(dp<mp[cnt])
                {
                    mp[cnt]=dp;
                    dmin=dp;
                }
            }
            else
            {
                if(dp<dmin)
                {
                    mp[++cnt]=dp;
                    dmin=dp;
                }
            }
        }
        else if(dp>0)
        {
            if(mp[cnt]>0)
            {
                if(dp>mp[cnt])
                {
                    mp[cnt]=dp;
                    dmax=dp;
                }
            }
            else
            {
                if(dp>dmax)
                {
                    mp[++cnt]=dp;
                    dmax=dp;
                }
            }
        }
    }
    if(mp[cnt]<0)
    {
        ans[1]-=mp[cnt];
        ans[n]+=mp[cnt-1];
    }
    else
    {
        ans[1]-=mp[cnt-1];
        ans[n]+=mp[cnt];
    }
    for(long long i=1;i<n;++i)
    {
        long long b=cb(1,cnt,x[i+1]-x[i]);
        if(b>cnt)
        {
            if(mp[cnt]<0)
            {
                ans[i+1]-=mp[cnt];
                ans[i]+=mp[cnt-1];
            }
            else
            {
                ans[i+1]-=mp[cnt-1];
                ans[i]+=mp[cnt];
            }
        }
        else
        {
            if(mp[b]<0)
            {
                ans[i]+=mp[b-1];
                ans[i+1]+=x[i+1]-x[i]-mp[b-1];
            }
            else
            {
                ans[i+1]-=mp[b-1];
                ans[i]+=x[i+1]-x[i]+mp[b-1];
            }
        }
    }
    for(long long i=1;i<=n;++i)
    {
        cout<<ans[i]<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 81 ms 1052 KB Output is correct
21 Correct 77 ms 1000 KB Output is correct
22 Correct 73 ms 964 KB Output is correct
23 Correct 67 ms 1084 KB Output is correct
24 Correct 74 ms 1492 KB Output is correct
25 Correct 193 ms 5712 KB Output is correct
26 Correct 183 ms 5700 KB Output is correct
27 Correct 182 ms 5428 KB Output is correct
28 Correct 204 ms 5428 KB Output is correct
29 Correct 174 ms 4912 KB Output is correct
30 Correct 153 ms 4164 KB Output is correct
31 Correct 139 ms 3788 KB Output is correct
32 Correct 137 ms 3780 KB Output is correct
33 Correct 19 ms 860 KB Output is correct
34 Correct 199 ms 9036 KB Output is correct
35 Correct 182 ms 8640 KB Output is correct
36 Correct 217 ms 9392 KB Output is correct
37 Correct 199 ms 8980 KB Output is correct
38 Correct 183 ms 9040 KB Output is correct
39 Correct 209 ms 9108 KB Output is correct
40 Correct 171 ms 9116 KB Output is correct
41 Correct 100 ms 2956 KB Output is correct
42 Correct 170 ms 6868 KB Output is correct
43 Correct 205 ms 11684 KB Output is correct
44 Correct 101 ms 4436 KB Output is correct
45 Correct 180 ms 9096 KB Output is correct
46 Correct 222 ms 11820 KB Output is correct
47 Correct 211 ms 10532 KB Output is correct
48 Correct 228 ms 10600 KB Output is correct