Submission #650474

# Submission time Handle Problem Language Result Execution time Memory
650474 2022-10-13T22:56:58 Z ymm Snowball (JOI21_ho_t2) C++17
100 / 100
121 ms 16992 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 200'010;
ll mn[N], mx[N], mxmn[N], sm[N];
ll ans[N];
ll x[N];
int n, q;

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> q;
	Loop (i,0,n)
		cin >> x[i];
	Loop (i,0,q) {
		cin >> sm[i+1];
		sm[i+1] += sm[i];
		mn[i+1] = min(mn[i], sm[i+1]);
		mx[i+1] = max(mx[i], sm[i+1]);
		mxmn[i+1] = mx[i+1] - mn[i+1];
	}
	mxmn[q+1] = 1e18;
	ans[0] += -mn[q];
	Loop (i,0,n-1) {
		int j = lower_bound(mxmn, mxmn+q+2, x[i+1]-x[i]) - mxmn;
		if (j > q) {
			ans[i] += mx[q];
			ans[i+1] += -mn[q];
		} else {
			--j;
			ans[i] += mx[j];
			ans[i+1] += -mn[j];
			ans[i + (sm[j+1]<sm[j])] += x[i+1]-x[i] - mxmn[j];
		}
	}
	ans[n-1] += mx[q];
	Loop (i,0,n)
		cout << ans[i] << '\n';
}
# 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 512 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 464 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 512 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 34 ms 8712 KB Output is correct
21 Correct 31 ms 8512 KB Output is correct
22 Correct 28 ms 8320 KB Output is correct
23 Correct 24 ms 8120 KB Output is correct
24 Correct 31 ms 8692 KB Output is correct
25 Correct 109 ms 14992 KB Output is correct
26 Correct 99 ms 14880 KB Output is correct
27 Correct 102 ms 14612 KB Output is correct
28 Correct 96 ms 14668 KB Output is correct
29 Correct 97 ms 14232 KB Output is correct
30 Correct 107 ms 13572 KB Output is correct
31 Correct 64 ms 13004 KB Output is correct
32 Correct 59 ms 13240 KB Output is correct
33 Correct 9 ms 1876 KB Output is correct
34 Correct 102 ms 15472 KB Output is correct
35 Correct 109 ms 14808 KB Output is correct
36 Correct 121 ms 15020 KB Output is correct
37 Correct 97 ms 14676 KB Output is correct
38 Correct 98 ms 14584 KB Output is correct
39 Correct 92 ms 14712 KB Output is correct
40 Correct 77 ms 14728 KB Output is correct
41 Correct 33 ms 9288 KB Output is correct
42 Correct 59 ms 13132 KB Output is correct
43 Correct 78 ms 16524 KB Output is correct
44 Correct 37 ms 9140 KB Output is correct
45 Correct 75 ms 14636 KB Output is correct
46 Correct 79 ms 16636 KB Output is correct
47 Correct 80 ms 16992 KB Output is correct
48 Correct 79 ms 16920 KB Output is correct