Submission #371256

# Submission time Handle Problem Language Result Execution time Memory
371256 2021-02-26T09:59:45 Z cheissmart Snowball (JOI21_ho_t2) C++14
100 / 100
130 ms 11500 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()

using namespace std;


void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t)) cerr << ", ";
	DBG(t...);
}
#define debug(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__);

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 200005;

ll x[N], w[N], ans[N], len[N], L[N], R[N];

signed main()
{
	IO_OP;
	
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> x[i];
	ll cur = 0, l = 0, r = 0;
	for(int i = 0; i < q; i++) {
		cin >> w[i];
		cur += w[i];
		r = max(r, cur);
		l = min(l, cur);
		len[i] = r - l;
		L[i] = l, R[i] = r;
	}
	ans[0] += -l, ans[n - 1] += r;
	for(int i = 0; i < n - 1; i++) {
		ll t = x[i + 1] - x[i];
		if(r - l <= t) {
			ans[i] += r, ans[i + 1] -= l;
		}
		else {
			int pos = upper_bound(len, len + q, t) - len;
			assert(pos < q);
			if(w[pos] > 0) { // r increase
				ans[i + 1] -= L[pos];
				ans[i] += t + L[pos];
			} else {
				ans[i] += R[pos];
				ans[i + 1] += t - R[pos];
			}
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i] << '\n';

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 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 0 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 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 0 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 31 ms 6636 KB Output is correct
21 Correct 37 ms 6764 KB Output is correct
22 Correct 32 ms 6636 KB Output is correct
23 Correct 27 ms 6636 KB Output is correct
24 Correct 35 ms 7148 KB Output is correct
25 Correct 119 ms 11352 KB Output is correct
26 Correct 118 ms 11372 KB Output is correct
27 Correct 113 ms 11116 KB Output is correct
28 Correct 117 ms 11116 KB Output is correct
29 Correct 116 ms 10988 KB Output is correct
30 Correct 105 ms 10604 KB Output is correct
31 Correct 67 ms 10220 KB Output is correct
32 Correct 64 ms 10092 KB Output is correct
33 Correct 11 ms 1516 KB Output is correct
34 Correct 116 ms 11372 KB Output is correct
35 Correct 123 ms 11244 KB Output is correct
36 Correct 130 ms 11400 KB Output is correct
37 Correct 117 ms 11116 KB Output is correct
38 Correct 119 ms 11228 KB Output is correct
39 Correct 108 ms 11244 KB Output is correct
40 Correct 81 ms 11116 KB Output is correct
41 Correct 35 ms 6636 KB Output is correct
42 Correct 63 ms 10092 KB Output is correct
43 Correct 87 ms 11372 KB Output is correct
44 Correct 34 ms 6636 KB Output is correct
45 Correct 72 ms 11116 KB Output is correct
46 Correct 97 ms 11500 KB Output is correct
47 Correct 93 ms 11500 KB Output is correct
48 Correct 91 ms 11404 KB Output is correct