Submission #998902

# Submission time Handle Problem Language Result Execution time Memory
998902 2024-06-14T21:59:42 Z DobromirAngelov Snowball (JOI21_ho_t2) C++14
100 / 100
61 ms 13908 KB
#include<bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second

using namespace std;

const int MAXN=2e5+5;

int n,q;
long long a[MAXN];
pair<long long,int> d[MAXN];
long long ans[MAXN];

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin>>n>>q;
for(int i=1;i<=n;i++) cin>>a[i];

for(int i=1;i<n;i++)
{
    d[i].fi=a[i+1]-a[i];
    d[i].se=i;
}

sort(d+1,d+n);

long long minPos=0,pos=0,maxPos=0;
int ptr=1;
for(int i=0;i<q;i++)
{
    long long w;
    cin>>w;
    pos+=w;
    if(w>=0)
    {
        maxPos=max(maxPos,pos);
        while(ptr<n && d[ptr].fi<=maxPos-minPos)
        {
            ans[d[ptr].se+1]-=minPos;
            ans[d[ptr].se]+=d[ptr].fi+minPos;
            ptr++;
        }
    }
    else
    {
        minPos=min(minPos, pos);
        while(ptr<n && d[ptr].fi<=maxPos-minPos)
        {
            ans[d[ptr].se]+=maxPos;
            ans[d[ptr].se+1]+=d[ptr].fi-maxPos;
            ptr++;
        }
    }
}
while(ptr<n)
{
    ans[d[ptr].se]+=maxPos;
    ans[d[ptr].se+1]-=minPos;
    ptr++;
}
ans[1]-=minPos;
ans[n]+=maxPos;

for(int i=1;i<=n;i++) cout<<ans[i]<<endl;

return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 532 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 516 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 532 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 516 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 16 ms 2388 KB Output is correct
21 Correct 15 ms 2396 KB Output is correct
22 Correct 14 ms 2000 KB Output is correct
23 Correct 14 ms 3932 KB Output is correct
24 Correct 17 ms 4440 KB Output is correct
25 Correct 55 ms 11860 KB Output is correct
26 Correct 57 ms 11760 KB Output is correct
27 Correct 56 ms 11408 KB Output is correct
28 Correct 54 ms 11556 KB Output is correct
29 Correct 61 ms 11092 KB Output is correct
30 Correct 53 ms 10580 KB Output is correct
31 Correct 49 ms 9876 KB Output is correct
32 Correct 43 ms 10120 KB Output is correct
33 Correct 6 ms 1628 KB Output is correct
34 Correct 54 ms 12192 KB Output is correct
35 Correct 52 ms 11576 KB Output is correct
36 Correct 54 ms 11860 KB Output is correct
37 Correct 53 ms 11604 KB Output is correct
38 Correct 55 ms 11600 KB Output is correct
39 Correct 55 ms 11600 KB Output is correct
40 Correct 54 ms 11604 KB Output is correct
41 Correct 17 ms 3012 KB Output is correct
42 Correct 46 ms 10068 KB Output is correct
43 Correct 48 ms 13396 KB Output is correct
44 Correct 19 ms 2892 KB Output is correct
45 Correct 56 ms 11716 KB Output is correct
46 Correct 51 ms 13904 KB Output is correct
47 Correct 53 ms 13652 KB Output is correct
48 Correct 56 ms 13908 KB Output is correct