Submission #562894

# Submission time Handle Problem Language Result Execution time Memory
562894 2022-05-15T13:38:59 Z dattranxxx Snowball (JOI21_ho_t2) C++11
33 / 100
167 ms 9160 KB
#include<bits/stdc++.h>
#define print(_v) for (auto& _e : _v) {cerr << _e << ' ';} cerr << '\n';
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
ll a[N], b[N], p[N], res[N];
int n, q;
vector<pair<ll, ll>> c;
void pre_calc() {
	for (int i = 1; i <= q; ++i)
		p[i] = p[i-1] + b[i];
	vector<ll> pos, neg;
	if (p[1] >= 0) neg.emplace_back(0);
	bool flag = 0;
	for (int i = 1; i <= q;) {
		int j = i; ll v = 0;
		if (p[i] >= 0) {
			while (j <= q && p[j] >= 0) v = max(v, p[j]), j++;
			pos.emplace_back(v);
		} else {
			while (j <= q && p[j] <= 0) v = min(v, p[j]), j++;
			neg.emplace_back(v);
			if (j == q + 1) flag = 1;
		}
		i = j;
	}
	c.clear();
	ll cur = 0;
	for (int i = 0; i < pos.size(); ++i) {
		cur = min(cur, neg[i]);
		if (c.empty() || pos[i] > c.back().first) 
			c.emplace_back(pos[i], cur);
	}
	if (flag) c.emplace_back(pos.empty() ? 0 : pos.back(), min(cur, neg.back()));
}
ll val(int i, int j) {
	return min(c[j].first, a[i+1] - a[i] + c[j].second);
}
int check(int i, int j) {
	return (j == 0 || val(i, j) > val(i, j-1)) 
			&& (val(i, j) >= val(i, j+1));
}
void solve(int f = 0) {
	// tim dinh cua day min(c[i].first, D + c[i].second) voi moi D
	for (int i = 1; i <= n; ++i) {
		if (c.size() == 1) {
			res[f ? n-i+1 : i] += max(0LL, val(i, 0)); continue;
		}
		int lo = 0, hi = int(c.size()) - 3, mid, 
		ans = val(i, c.size() - 1) > val(i, c.size() - 2) ? c.size() - 1 : c.size() - 2; 
		while (lo <= hi) {
			mid = (lo + hi) >> 1;
			if (check(i, mid))	
				ans = mid, lo = hi + 1;
			else if (val(i, mid) < val(i, mid + 1))
				lo = mid + 1;
			else 
				hi = mid - 1;
		}
		res[f ? n-i+1 : i] += max(0LL ,val(i, ans));
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0); cout.tie(0);
	// min(pre[i], D - min[i])
	// -> day tang roi giam
	cin >> n >> q;
	a[n + 1] = 1e17;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i <= q; ++i)
		cin >> b[i];
	pre_calc();
	solve();
	for (int i = 1; i <= n; ++i)
		a[i] = -a[i];
	reverse(a + 1, a + n + 1);
	for (int i = 1; i <= q; ++i)
		b[i] = -b[i];
	pre_calc();
	solve(1);
	for (int i = 1; i <= n; ++i)
		cout << res[i] << '\n';
	return 0;
}

Compilation message

Main.cpp: In function 'void pre_calc()':
Main.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < pos.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
# 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 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 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 2 ms 340 KB Output is correct
11 Correct 2 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 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 2 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 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 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 2 ms 340 KB Output is correct
11 Correct 2 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 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 39 ms 5456 KB Output is correct
21 Correct 31 ms 5468 KB Output is correct
22 Correct 31 ms 5520 KB Output is correct
23 Correct 29 ms 5488 KB Output is correct
24 Correct 50 ms 5756 KB Output is correct
25 Correct 163 ms 9012 KB Output is correct
26 Correct 146 ms 9024 KB Output is correct
27 Correct 164 ms 8744 KB Output is correct
28 Correct 154 ms 8900 KB Output is correct
29 Correct 167 ms 8324 KB Output is correct
30 Correct 104 ms 8200 KB Output is correct
31 Correct 66 ms 7848 KB Output is correct
32 Correct 58 ms 6980 KB Output is correct
33 Correct 18 ms 1596 KB Output is correct
34 Correct 130 ms 8480 KB Output is correct
35 Correct 132 ms 8624 KB Output is correct
36 Correct 156 ms 9160 KB Output is correct
37 Correct 145 ms 8880 KB Output is correct
38 Correct 159 ms 8768 KB Output is correct
39 Correct 156 ms 9008 KB Output is correct
40 Correct 151 ms 9024 KB Output is correct
41 Incorrect 33 ms 3608 KB Output isn't correct
42 Halted 0 ms 0 KB -