Submission #964393

# Submission time Handle Problem Language Result Execution time Memory
964393 2024-04-16T18:34:46 Z maxFedorchuk Snowball (JOI21_ho_t2) C++17
100 / 100
82 ms 18836 KB
#include <bits/stdc++.h>
using namespace std;

const long long MX=2e5+10;
long long x[MX],w[MX],ans[MX];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    long long n,m;
    cin>>n>>m;

    for(long long i=1;i<=n;i++)
    {
        cin>>x[i];
    }

    for(long long i=1;i<=m;i++)
    {
        cin>>w[i];
        w[i]+=w[i-1];
    }

    vector < long long > imt;
    vector < long long > sum;
    vector < long long > mnz;
    vector < long long > mxz;
    imt.push_back(0);
    mnz.push_back(0);
    mxz.push_back(0);

    long long mn=0,mx=0;
    for(long long i=1;i<=m;i++)
    {
        if(w[i]<mn)
        {
            imt.push_back(w[i]);
            mnz.push_back(w[i]);
            mxz.push_back(mxz.back());
            mn=w[i];
        }

        if(w[i]>mx)
        {
            imt.push_back(w[i]);
            mnz.push_back(mnz.back());
            mxz.push_back(w[i]);
            mx=w[i];
        }
    }

    m=imt.size()-1;
    for(long long i=0;i<=m;i++)
    {
        sum.push_back(llabs(mxz[i])+llabs(mnz[i]));
    }

    for(long long i=2;i<=n;i++)
    {
        long long l=0,r=m+1;

        while(l+1<r)
        {
            long long mid=(l+r)/2;
            if(sum[mid]<=(x[i]-x[i-1]))
            {
                l=mid;
            }
            else
            {
                r=mid;
            }
        }

        ans[i-1]+=llabs(mxz[l]);
        ans[i]+=llabs(mnz[l]);

        if(r==m+1)
        {
            continue;
        }

        if(imt[r]<0)
        {
            ans[i]+=(x[i]-x[i-1])-sum[l];
        }
        else
        {
            ans[i-1]+=(x[i]-x[i-1])-sum[l];
        }
    }

    ans[1]+=llabs(mnz[m]);
    ans[n]+=llabs(mxz[m]);

    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4696 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4568 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4704 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4696 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4568 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4704 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4556 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 29 ms 14772 KB Output is correct
21 Correct 24 ms 14268 KB Output is correct
22 Correct 22 ms 14000 KB Output is correct
23 Correct 22 ms 13904 KB Output is correct
24 Correct 27 ms 13744 KB Output is correct
25 Correct 77 ms 16684 KB Output is correct
26 Correct 74 ms 16636 KB Output is correct
27 Correct 75 ms 15788 KB Output is correct
28 Correct 82 ms 15516 KB Output is correct
29 Correct 68 ms 12348 KB Output is correct
30 Correct 53 ms 9040 KB Output is correct
31 Correct 41 ms 8532 KB Output is correct
32 Correct 36 ms 8508 KB Output is correct
33 Correct 9 ms 5724 KB Output is correct
34 Correct 67 ms 10960 KB Output is correct
35 Correct 64 ms 10736 KB Output is correct
36 Correct 82 ms 16468 KB Output is correct
37 Correct 81 ms 14972 KB Output is correct
38 Correct 75 ms 15780 KB Output is correct
39 Correct 71 ms 16044 KB Output is correct
40 Correct 56 ms 16048 KB Output is correct
41 Correct 25 ms 15020 KB Output is correct
42 Correct 42 ms 8612 KB Output is correct
43 Correct 58 ms 18224 KB Output is correct
44 Correct 33 ms 14740 KB Output is correct
45 Correct 62 ms 16048 KB Output is correct
46 Correct 57 ms 18372 KB Output is correct
47 Correct 55 ms 14532 KB Output is correct
48 Correct 61 ms 18836 KB Output is correct