Submission #1102536

# Submission time Handle Problem Language Result Execution time Memory
1102536 2024-10-18T08:51:14 Z NotLinux Snowball (JOI21_ho_t2) C++17
100 / 100
261 ms 28248 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int inf = 1e18 + 7;
void solve(){
	int n,q;
	cin >> n >> q;
	int arr[n];
	for(int i = 0;i<n;i++)cin >> arr[i];
	int query[q] , sum = 0 , premin[q] , premax[q];
	for(int i = 0;i<q;i++){
		cin >> query[i];
	}
	map < int , int > mpa;// first time reaching sum
	mpa[0] = -1;
	for(int i = 0;i<q;i++){
		sum += query[i];
		premin[i] = min(i == 0 ? 0 : premin[i-1] , sum);
		premax[i] = max(i == 0 ? 0 : premax[i-1] , sum);
		if(mpa.count(sum) == 0){
			mpa[sum] = i;
		}
	}
	int ans[n] = {0};
	ans[0] += abs(premin[q-1]);
	ans[n-1] += premax[q-1];
	for(int i = 0;i<n-1;i++){
		int l = 0 , r = q;
		while(l < r){
			int mid = (l + r) / 2;
			if((arr[i] + premax[mid]) >= (arr[i+1] + premin[mid]))r = mid;
			else l = mid+1;
		}
		// cout << i << " : " << arr[i] << " " << arr[i+1] << endl;
		if(l == q){// they dont collide
			ans[i] += premax[q-1];
			ans[i+1] += abs(premin[q-1]);
			// cout << "didnt collide" << endl;
		}
		else{
			int point;// arr[i] moves till point , arr[i+1] moves till point+1
			if(mpa[premax[l]] < mpa[premin[l]]){
				point = arr[i] + premax[l];
			}
			else{
				point = arr[i+1] + premin[l];
			}
			// cout << "collide at : " << point << endl;
			ans[i] += point - arr[i];
			ans[i+1] += arr[i+1] - point;
		}
	}
	for(int i = 0;i<n;i++){
		cout << ans[i] << '\n';
	}
	// cout << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
	cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
/*	
 * dont get stuck on one approach , try different ones
 * if you think the implementation is long & messy , change your approach
 * think simple , dont overkill
 */
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 67 ms 19556 KB Output is correct
21 Correct 57 ms 19540 KB Output is correct
22 Correct 57 ms 19332 KB Output is correct
23 Correct 64 ms 19276 KB Output is correct
24 Correct 69 ms 19756 KB Output is correct
25 Correct 239 ms 25932 KB Output is correct
26 Correct 235 ms 25676 KB Output is correct
27 Correct 212 ms 24516 KB Output is correct
28 Correct 219 ms 23568 KB Output is correct
29 Correct 200 ms 18128 KB Output is correct
30 Correct 93 ms 12224 KB Output is correct
31 Correct 54 ms 11596 KB Output is correct
32 Correct 47 ms 11724 KB Output is correct
33 Correct 17 ms 2892 KB Output is correct
34 Correct 261 ms 26544 KB Output is correct
35 Correct 260 ms 24660 KB Output is correct
36 Correct 259 ms 25932 KB Output is correct
37 Correct 230 ms 24536 KB Output is correct
38 Correct 216 ms 24408 KB Output is correct
39 Correct 178 ms 24652 KB Output is correct
40 Correct 107 ms 24652 KB Output is correct
41 Correct 84 ms 20300 KB Output is correct
42 Correct 46 ms 11612 KB Output is correct
43 Correct 139 ms 27468 KB Output is correct
44 Correct 93 ms 20236 KB Output is correct
45 Correct 78 ms 24528 KB Output is correct
46 Correct 124 ms 27608 KB Output is correct
47 Correct 86 ms 19412 KB Output is correct
48 Correct 137 ms 28248 KB Output is correct