Submission #798558

# Submission time Handle Problem Language Result Execution time Memory
798558 2023-07-30T20:30:14 Z denniskim Snowball (JOI21_ho_t2) C++17
100 / 100
128 ms 16888 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n, q;
ll a[200010];
ll b[200010];
ll nu[200010];
ll maxx[200010], minn[200010];
ll ans[200010];

int main(void)
{
	fastio
	
	cin >> n >> q;
	
	for(ll i = 1 ; i <= n ; i++)
		cin >> a[i];
	
	for(ll i = 1 ; i <= q ; i++)
	{
		cin >> b[i];
		nu[i] = nu[i - 1] + b[i];
	}
	
	for(ll i = 1 ; i <= q ; i++)
	{
		maxx[i] = maxx[i - 1];
		minn[i] = minn[i - 1];
		
		if(nu[i] > 0)
			maxx[i] = max(maxx[i], nu[i]);
		
		if(nu[i] < 0)
			minn[i] = max(minn[i], -nu[i]);
	}
	
	a[0] = -INF;
	a[n + 1] = INF;
	
	for(ll i = 1 ; i <= n ; i++)
	{
		ll dist = a[i] - a[i - 1];
		ll l = 1, r = q;
		
		while(l <= r)
		{
			ll mid = (l + r) >> 1;
			
			if(maxx[mid] + minn[mid] >= dist)
				r = mid - 1;
			else
				l = mid + 1;
		}
		
		if(l == q + 1)
		{
			ans[i] += minn[q];
			continue;
		}
		
		if(nu[l] > 0)
			ans[i] += minn[l];
		else
			ans[i] += dist - maxx[l];
	}
	
	for(ll i = 1 ; i <= n ; i++)
	{
		ll dist = a[i + 1] - a[i];
		ll l = 1, r = q;
		
		while(l <= r)
		{
			ll mid = (l + r) >> 1;
			
			if(maxx[mid] + minn[mid] >= dist)
				r = mid - 1;
			else
				l = mid + 1;
		}
		
		if(l == q + 1)
		{
			ans[i] += maxx[q];
			continue;
		}
		
		if(nu[l] > 0)
			ans[i] += dist - minn[l];
		else
			ans[i] += maxx[l];
	}
	
	for(ll i = 1 ; i <= n ; i++)
		cout << ans[i] en;
	
	return 0;
}
# 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 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 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 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 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 468 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 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 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 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 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 468 KB Output is correct
20 Correct 24 ms 8660 KB Output is correct
21 Correct 21 ms 8508 KB Output is correct
22 Correct 19 ms 8276 KB Output is correct
23 Correct 19 ms 8196 KB Output is correct
24 Correct 27 ms 8684 KB Output is correct
25 Correct 108 ms 14924 KB Output is correct
26 Correct 108 ms 14904 KB Output is correct
27 Correct 107 ms 14524 KB Output is correct
28 Correct 108 ms 14668 KB Output is correct
29 Correct 117 ms 14240 KB Output is correct
30 Correct 103 ms 13604 KB Output is correct
31 Correct 57 ms 12976 KB Output is correct
32 Correct 48 ms 13200 KB Output is correct
33 Correct 9 ms 1872 KB Output is correct
34 Correct 125 ms 15264 KB Output is correct
35 Correct 125 ms 14744 KB Output is correct
36 Correct 108 ms 15000 KB Output is correct
37 Correct 111 ms 14652 KB Output is correct
38 Correct 128 ms 14548 KB Output is correct
39 Correct 106 ms 14728 KB Output is correct
40 Correct 65 ms 14736 KB Output is correct
41 Correct 21 ms 9308 KB Output is correct
42 Correct 46 ms 13192 KB Output is correct
43 Correct 59 ms 16540 KB Output is correct
44 Correct 22 ms 9124 KB Output is correct
45 Correct 52 ms 14644 KB Output is correct
46 Correct 61 ms 16640 KB Output is correct
47 Correct 62 ms 16880 KB Output is correct
48 Correct 60 ms 16888 KB Output is correct