Submission #529511

# Submission time Handle Problem Language Result Execution time Memory
529511 2022-02-23T05:39:15 Z abc864197532 Snowball (JOI21_ho_t2) C++17
100 / 100
314 ms 11436 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 200000;

int main () {
	owo;
	int n, q;
	cin >> n >> q;
	vector <lli> a(n);
	lli move_mx = 0, move_mn = 0, now = 0, x;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	vector <lli> ans(n);
	vector <int> p(n);
	iota(all(p), 0);
	sort(p.begin(), p.begin() + n - 1, [&](int i, int j) {
		return a[i + 1] - a[i] < a[j + 1] - a[j];
	});
	int j = 0;
	for (int i = 0; i < q; ++i) {
		cin >> x, now += x;
		move_mx = max(move_mx, now);
		move_mn = min(move_mn, now);
		while (j < n - 1 && a[p[j] + 1] - a[p[j]] <= move_mx - move_mn) {
			lli d = a[p[j] + 1] - a[p[j]];
			if (x < 0) {
				ans[p[j]] += move_mx, ans[p[j] + 1] += d - move_mx;
			} else {
				ans[p[j] + 1] += -move_mn, ans[p[j]] += d + move_mn;
			}
			j++;
		}
	}
	while (j < n - 1) {
		ans[p[j]] += move_mx, ans[p[j] + 1] += -move_mn;
		j++;
	}
	ans[0] += -move_mn, ans[n - 1] += move_mx;
	for (lli i : ans)
		cout << i << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 400 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 400 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 400 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 400 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 27 ms 2340 KB Output is correct
21 Correct 29 ms 2212 KB Output is correct
22 Correct 23 ms 1960 KB Output is correct
23 Correct 22 ms 1856 KB Output is correct
24 Correct 60 ms 2496 KB Output is correct
25 Correct 303 ms 9540 KB Output is correct
26 Correct 291 ms 9464 KB Output is correct
27 Correct 290 ms 9148 KB Output is correct
28 Correct 303 ms 9300 KB Output is correct
29 Correct 314 ms 8768 KB Output is correct
30 Correct 283 ms 8176 KB Output is correct
31 Correct 267 ms 7624 KB Output is correct
32 Correct 279 ms 7748 KB Output is correct
33 Correct 45 ms 1228 KB Output is correct
34 Correct 314 ms 9784 KB Output is correct
35 Correct 285 ms 9356 KB Output is correct
36 Correct 295 ms 9540 KB Output is correct
37 Correct 295 ms 9428 KB Output is correct
38 Correct 290 ms 9112 KB Output is correct
39 Correct 284 ms 9292 KB Output is correct
40 Correct 280 ms 9296 KB Output is correct
41 Correct 27 ms 3012 KB Output is correct
42 Correct 277 ms 7744 KB Output is correct
43 Correct 279 ms 11068 KB Output is correct
44 Correct 28 ms 2884 KB Output is correct
45 Correct 283 ms 9408 KB Output is correct
46 Correct 286 ms 11076 KB Output is correct
47 Correct 288 ms 11352 KB Output is correct
48 Correct 287 ms 11436 KB Output is correct