Submission #602196

# Submission time Handle Problem Language Result Execution time Memory
602196 2022-07-22T16:43:43 Z HamletPetrosyan Snowball (JOI21_ho_t2) C++17
100 / 100
88 ms 13800 KB
/// #if (code == true)

#include <bits/stdc++.h>
using namespace std;

#define pll pair<long long, long long>
#define len(a) ((int)((a).size()))
#define all(a) a.begin(), a.end()
#define add push_back
#define mkp make_pair
#define ll long long
#define fr first
#define sc second

const long long INF = 1000000000ll * 1000000003ll;
const long long MOD = 1000000007ll;
const int N = 2e5 + 5;

ll n, q;
ll x[N], w, ans[N];
pll dist[N];

void solve(){
	cin >> n >> q;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		if(i > 0) dist[i] = {x[i] - x[i - 1], i};
	}
	sort(dist + 1, dist + n);
	ll now = 0, r = 0, l = 0, ind = 1;
	while(q--){
		cin >> w;
		now += w;
		l = max(l, -now);
		r = max(r, +now);
		while(dist[ind].fr < l + r && ind < n){
			if(w > 0){
				ans[dist[ind].sc] += l;
				ans[dist[ind].sc - 1] += dist[ind].fr - l;
			}
			else{
				ans[dist[ind].sc - 1] += r;
				ans[dist[ind].sc] += dist[ind].fr - r;
			}
			ind++;
		}
	}
	while(ind < n){
		ans[dist[ind].sc] += l;
		ans[dist[ind].sc - 1] += r;
		ind++;
	}
	ans[0] += l;
	ans[n - 1] += r;
	for(int i = 0; i < n; i++){
		cout << ans[i] << "\n";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int _ = 1;
	// cout << fixed;
	// cout.precision(15);

	// cin >> _ ;
	while(_--) solve();
	return 0;
}

/// #else
/// #include <bits/stdc++.h> using namespace std; int main() { cout << "Hello World!"; }
/// #endif
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 392 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 392 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 28 ms 2356 KB Output is correct
21 Correct 24 ms 2248 KB Output is correct
22 Correct 25 ms 1976 KB Output is correct
23 Correct 19 ms 1972 KB Output is correct
24 Correct 23 ms 2728 KB Output is correct
25 Correct 88 ms 11888 KB Output is correct
26 Correct 78 ms 11800 KB Output is correct
27 Correct 75 ms 11468 KB Output is correct
28 Correct 74 ms 11664 KB Output is correct
29 Correct 82 ms 11024 KB Output is correct
30 Correct 71 ms 10488 KB Output is correct
31 Correct 76 ms 9956 KB Output is correct
32 Correct 55 ms 10032 KB Output is correct
33 Correct 8 ms 1492 KB Output is correct
34 Correct 75 ms 12180 KB Output is correct
35 Correct 71 ms 11528 KB Output is correct
36 Correct 72 ms 11772 KB Output is correct
37 Correct 77 ms 11552 KB Output is correct
38 Correct 75 ms 11376 KB Output is correct
39 Correct 75 ms 11728 KB Output is correct
40 Correct 72 ms 11652 KB Output is correct
41 Correct 28 ms 3020 KB Output is correct
42 Correct 67 ms 9996 KB Output is correct
43 Correct 73 ms 13292 KB Output is correct
44 Correct 29 ms 2860 KB Output is correct
45 Correct 73 ms 11508 KB Output is correct
46 Correct 79 ms 13460 KB Output is correct
47 Correct 79 ms 13772 KB Output is correct
48 Correct 82 ms 13800 KB Output is correct