Submission #1020316

# Submission time Handle Problem Language Result Execution time Memory
1020316 2024-07-11T22:24:27 Z AndrijaM Snowball (JOI21_ho_t2) C++17
100 / 100
336 ms 12364 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int logn=20;

pair<int,int>lr[maxn];
int n,k,cnt=0;
int x[maxn];

int bs(int n)
{
    int l=0;
    int r=cnt-1;
    while(l<r)
    {
        int mid=l+(r-l+1)/2;
        if(lr[mid].second-lr[mid].first<=n)
        {
            l=mid;
        }
        else
        {
            r=mid-1;
        }
    }
    return l;
}

signed main()
{
    ///freopen("deleg.in","r",stdin);
    ///freopen("deleg.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    int sum=0;
    int l=0;
    int r=0;
    lr[cnt]={0,0};
    cnt++;
    for(int i=0;i<k;i++)
    {
        int a;
        cin>>a;
        sum+=a;
        l=min(l,sum);
        r=max(r,sum);
        if(lr[cnt-1]==pair<int,int>{l,r})continue;
        else
        {
            lr[cnt]={l,r};
            cnt++;
        }
    }
    for(int i=0;i<n;i++)
    {
        int ans=0;
        if(i==n-1)
        {
            ans+=abs(r);
        }
        else
        {
            int len=x[i+1]-x[i];
            int idx=bs(len);
            if(idx==cnt-1 || lr[idx].second==lr[idx+1].second)
            {
                ans+=lr[idx].second;
            }
            else
            {
                ans+=len+lr[idx].first;
            }
        }
        if(i==0)
        {
            ans+=abs(l);
        }
        else
        {
            int len=x[i]-x[i-1];
            int idx=bs(len);
            if(idx==cnt-1 || lr[idx].first==lr[idx+1].first)
            {
                ans+=-lr[idx].first;
            }
            else
            {
                ans+=len-lr[idx].second;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 424 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 3 ms 556 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 424 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 3 ms 556 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 16 ms 5464 KB Output is correct
21 Correct 18 ms 5472 KB Output is correct
22 Correct 15 ms 5200 KB Output is correct
23 Correct 18 ms 4956 KB Output is correct
24 Correct 41 ms 5452 KB Output is correct
25 Correct 318 ms 10360 KB Output is correct
26 Correct 311 ms 10128 KB Output is correct
27 Correct 299 ms 9764 KB Output is correct
28 Correct 295 ms 9668 KB Output is correct
29 Correct 296 ms 7760 KB Output is correct
30 Correct 272 ms 5968 KB Output is correct
31 Correct 236 ms 5316 KB Output is correct
32 Correct 227 ms 5456 KB Output is correct
33 Correct 28 ms 1360 KB Output is correct
34 Correct 261 ms 7764 KB Output is correct
35 Correct 314 ms 7248 KB Output is correct
36 Correct 336 ms 10068 KB Output is correct
37 Correct 291 ms 9272 KB Output is correct
38 Correct 293 ms 9624 KB Output is correct
39 Correct 279 ms 9808 KB Output is correct
40 Correct 242 ms 9756 KB Output is correct
41 Correct 18 ms 6232 KB Output is correct
42 Correct 217 ms 5340 KB Output is correct
43 Correct 241 ms 11860 KB Output is correct
44 Correct 17 ms 5968 KB Output is correct
45 Correct 242 ms 9860 KB Output is correct
46 Correct 249 ms 12040 KB Output is correct
47 Correct 247 ms 10020 KB Output is correct
48 Correct 254 ms 12364 KB Output is correct