Submission #381247

# Submission time Handle Problem Language Result Execution time Memory
381247 2021-03-24T22:55:51 Z limabeans Snowball (JOI21_ho_t2) C++17
100 / 100
126 ms 14300 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const ll inf = 1e18;

const int maxn = 2e5 + 10;



int n,q;


ll x[maxn];
ll ans[maxn];


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

    cin>>n>>q;

    for (int i=1; i<=n; i++) {
	cin>>x[i];
    }
    x[0]=-inf;
    x[n+1]=inf;

    vector<pair<ll,int>> t;
    for (int i=0; i<=n; i++) {
	t.push_back({x[i+1]-x[i],i});
    }


    sort(t.begin(), t.end());

    int idx = 0;
    ll L = 0;
    ll R = 0;
    ll at = 0;


    while (q--) {
	ll w;
	cin>>w;
	at += w;
	
	if (w>=0) {
	    R = max(R, at);
	    while (idx<=n && t[idx].first<L+R) {
		ans[t[idx].second+1] += L;
		ans[t[idx].second] += (t[idx].first-L);
		idx++;
	    }
	} else {
	    L = max(L, -at);
	    while (idx<=n && t[idx].first<L+R) {
		ans[t[idx].second] += R;
		ans[t[idx].second+1] += (t[idx].first-R);
		idx++;
	    }
	}
    }


    while (idx<=n) {
	ans[t[idx].second] += R;
	ans[t[idx].second+1] += L;
	idx++;
    }

    for (int i=1; i<=n; i++) {
	cout<<ans[i]<<"\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 32 ms 2540 KB Output is correct
21 Correct 29 ms 2284 KB Output is correct
22 Correct 29 ms 2156 KB Output is correct
23 Correct 34 ms 2028 KB Output is correct
24 Correct 31 ms 2924 KB Output is correct
25 Correct 105 ms 12148 KB Output is correct
26 Correct 107 ms 12008 KB Output is correct
27 Correct 100 ms 11612 KB Output is correct
28 Correct 101 ms 11996 KB Output is correct
29 Correct 99 ms 11356 KB Output is correct
30 Correct 97 ms 10716 KB Output is correct
31 Correct 92 ms 10156 KB Output is correct
32 Correct 74 ms 10332 KB Output is correct
33 Correct 11 ms 1644 KB Output is correct
34 Correct 100 ms 12380 KB Output is correct
35 Correct 96 ms 11868 KB Output is correct
36 Correct 100 ms 12124 KB Output is correct
37 Correct 99 ms 11868 KB Output is correct
38 Correct 104 ms 11612 KB Output is correct
39 Correct 102 ms 11996 KB Output is correct
40 Correct 97 ms 11868 KB Output is correct
41 Correct 32 ms 3052 KB Output is correct
42 Correct 88 ms 10332 KB Output is correct
43 Correct 126 ms 13532 KB Output is correct
44 Correct 40 ms 2956 KB Output is correct
45 Correct 97 ms 11752 KB Output is correct
46 Correct 106 ms 13660 KB Output is correct
47 Correct 102 ms 13976 KB Output is correct
48 Correct 115 ms 14300 KB Output is correct