Submission #543676

# Submission time Handle Problem Language Result Execution time Memory
543676 2022-03-31T08:16:44 Z Asymmetry Snowball (JOI21_ho_t2) C++17
100 / 100
174 ms 16932 KB
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif

const int N = 201000;
int n, q;
long long odp[N];
long long t[N];
long long w[N];
long long pw[N];
long long pref_min[N];
long long pref_max[N];

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &t[i]);
	}
	for (int i = 1; i <= q; ++i) {
		scanf("%lld", &w[i]);
		pw[i] = pw[i - 1] + w[i];
		pref_min[i] = min(pref_min[i - 1], pw[i]);
		pref_max[i] = max(pref_max[i - 1], pw[i]);
	}
	odp[1] -= pref_min[q];
	odp[n] += pref_max[q];
	for (int i = 1; i < n; ++i) {
		long long dif = t[i + 1] - t[i];
		int bp = 0, bk = q + 1, bs;
		while (bk - bp > 1) {
			bs = (bp + bk) / 2;
			if (pref_max[bs] - pref_min[bs] < dif) {
				bp = bs;
			}
			else {
				bk = bs;
			}
		}
		debug(t[i], t[i + 1], bk, pref_min[bk], pref_max[bk]);
		if (bk == q + 1) {
			odp[i] += pref_max[q];
			odp[i + 1] -= pref_min[q];
		}
		else if (w[bk] < 0) {
			odp[i] += pref_max[bk];
			odp[i + 1] += dif - pref_max[bk];
		}
		else {
			debug("c", -pref_min[bk], dif + pref_min[bk]);
			odp[i + 1] -= pref_min[bk];
			odp[i] += dif + pref_min[bk];
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%lld\n", odp[i]);
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%lld", &t[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%lld", &w[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 30 ms 8652 KB Output is correct
21 Correct 27 ms 8456 KB Output is correct
22 Correct 27 ms 8264 KB Output is correct
23 Correct 25 ms 8120 KB Output is correct
24 Correct 36 ms 8608 KB Output is correct
25 Correct 174 ms 14924 KB Output is correct
26 Correct 116 ms 14940 KB Output is correct
27 Correct 116 ms 14596 KB Output is correct
28 Correct 130 ms 14716 KB Output is correct
29 Correct 146 ms 14240 KB Output is correct
30 Correct 112 ms 13576 KB Output is correct
31 Correct 89 ms 13020 KB Output is correct
32 Correct 83 ms 13232 KB Output is correct
33 Correct 11 ms 1864 KB Output is correct
34 Correct 108 ms 15252 KB Output is correct
35 Correct 128 ms 14728 KB Output is correct
36 Correct 131 ms 15084 KB Output is correct
37 Correct 110 ms 14680 KB Output is correct
38 Correct 134 ms 14588 KB Output is correct
39 Correct 106 ms 14696 KB Output is correct
40 Correct 93 ms 14824 KB Output is correct
41 Correct 33 ms 9292 KB Output is correct
42 Correct 81 ms 13196 KB Output is correct
43 Correct 104 ms 16440 KB Output is correct
44 Correct 40 ms 9164 KB Output is correct
45 Correct 85 ms 14696 KB Output is correct
46 Correct 95 ms 16616 KB Output is correct
47 Correct 122 ms 16768 KB Output is correct
48 Correct 104 ms 16932 KB Output is correct