Submission #397678

# Submission time Handle Problem Language Result Execution time Memory
397678 2021-05-02T20:01:41 Z ChrisT Snowball (JOI21_ho_t2) C++17
100 / 100
155 ms 15300 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e6 + 5;
int main () {
	int n,q; scanf ("%d %d",&n,&q);
	vector<long long> x(n), go(q);
	for (int i = 0; i < n; i++) scanf ("%lld",&x[i]);
	for (int i = 0; i < q; i++) scanf ("%lld",&go[i]);
	vector<long long> left(q), right(q);
	long long pre = 0;
	for (int i = 0; i < q; i++) {
		pre += go[i];
		left[i] = min(pre,i?left[i-1]:0LL);
		right[i] = max(pre,i?right[i-1]:0LL);
	}
	vector<long long> ret(n);
	for (int i = 1; i < n; i++) {
		int low = 0, high = q-1, mid, ans = -1;
		while (low <= high) {
			mid = (low + high) / 2;
			if (x[i-1] + right[mid] >= x[i] + left[mid]) high = (ans = mid) - 1;
			else low = mid + 1;
		}
		if (ans == -1) ret[i-1] += right[q-1], ret[i] -= left[q-1];
		else if (go[ans] > 0) {
			long long cut = x[i] + left[ans];
			ret[i] += x[i] - cut;
			ret[i-1] += cut - x[i-1];
		} else {
			long long cut = x[i-1] + right[ans];
			ret[i-1] += cut - x[i-1];
			ret[i] += x[i] - cut;
		}
	}
	ret[0] -= left[q-1]; ret[n-1] += right[q-1];
	for (int i = 0; i < n; i++) printf ("%lld\n",ret[i]);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:5:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    5 |  int n,q; scanf ("%d %d",&n,&q);
      |           ~~~~~~^~~~~~~~~~~~~~~
Main.cpp:7:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  for (int i = 0; i < n; i++) scanf ("%lld",&x[i]);
      |                              ~~~~~~^~~~~~~~~~~~~~
Main.cpp:8:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  for (int i = 0; i < q; i++) scanf ("%lld",&go[i]);
      |                              ~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 304 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 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 304 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 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 38 ms 7096 KB Output is correct
21 Correct 35 ms 6840 KB Output is correct
22 Correct 42 ms 6724 KB Output is correct
23 Correct 32 ms 6576 KB Output is correct
24 Correct 40 ms 7016 KB Output is correct
25 Correct 130 ms 13400 KB Output is correct
26 Correct 148 ms 13260 KB Output is correct
27 Correct 123 ms 13016 KB Output is correct
28 Correct 125 ms 13128 KB Output is correct
29 Correct 155 ms 12632 KB Output is correct
30 Correct 115 ms 11972 KB Output is correct
31 Correct 112 ms 11460 KB Output is correct
32 Correct 86 ms 11684 KB Output is correct
33 Correct 12 ms 1612 KB Output is correct
34 Correct 127 ms 13764 KB Output is correct
35 Correct 130 ms 13144 KB Output is correct
36 Correct 136 ms 13408 KB Output is correct
37 Correct 126 ms 13252 KB Output is correct
38 Correct 131 ms 13000 KB Output is correct
39 Correct 127 ms 13228 KB Output is correct
40 Correct 93 ms 13144 KB Output is correct
41 Correct 38 ms 7612 KB Output is correct
42 Correct 83 ms 11608 KB Output is correct
43 Correct 127 ms 14940 KB Output is correct
44 Correct 39 ms 7480 KB Output is correct
45 Correct 88 ms 13132 KB Output is correct
46 Correct 105 ms 15044 KB Output is correct
47 Correct 107 ms 15300 KB Output is correct
48 Correct 107 ms 15300 KB Output is correct