Submission #532553

# Submission time Handle Problem Language Result Execution time Memory
532553 2022-03-03T07:22:57 Z Nanashi_Panda Snowball (JOI21_ho_t2) C++14
100 / 100
96 ms 13228 KB
#include <bits/stdc++.h>
//	#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//	#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define ll long long
using namespace std;
ll n, q;
ll x[200005];
ll h[200005];
ll rag[200005][2];
ll ans[200005];
struct line{
	ll i, v;
};
vector <line> val;
bool operator <(line a, line b){
	return a.v<b.v;
}

int main() {
	scanf("%lld%lld", &n, &q);
	for(ll i = 0; i < n; i++) scanf("%lld", x+i);
	for(ll i = 0; i < q; i++) scanf("%lld", h+i);
	ll now = 0;
	for(ll i = 1; i <= q; i++){
		now+=h[i-1];
		rag[i][0] = min(rag[i-1][0], now);
		rag[i][1] = max(rag[i-1][1], now);
	}
	for(ll i = 0; i < n-1; i++){
		val.push_back({i,x[i+1]-x[i]});
	}
	sort(val.begin(), val.end());
	ll ind = 0;
	if(n>1){
		for(ll i = 1; i <= q; i++){
			while(ind<n-1&&val[ind].v<=rag[i][1]-rag[i][0]){
				ans[val[ind].i]+=rag[i-1][1];
				ans[val[ind].i+1]-=rag[i-1][0];
				if(h[i-1]>0){
					ans[val[ind].i]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
				}else{
					ans[val[ind].i+1]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
				}
				ind++;
				if(ind>=n-1) break;
			}
		}
		for(ll i = ind; i < n-1; i++){
			ans[val[i].i]+=rag[q][1];
			ans[val[i].i+1]-=rag[q][0];
		}
	}
	ans[n-1]+=rag[q][1];
	ans[0]-=rag[q][0];
	for(ll i = 0; i < n; i++) printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%lld%lld", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:23:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  for(ll i = 0; i < n; i++) scanf("%lld", x+i);
      |                            ~~~~~^~~~~~~~~~~~~
Main.cpp:24:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  for(ll i = 0; i < q; i++) scanf("%lld", h+i);
      |                            ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 28 ms 5188 KB Output is correct
21 Correct 31 ms 5172 KB Output is correct
22 Correct 28 ms 5236 KB Output is correct
23 Correct 24 ms 5332 KB Output is correct
24 Correct 28 ms 6172 KB Output is correct
25 Correct 84 ms 13192 KB Output is correct
26 Correct 85 ms 13096 KB Output is correct
27 Correct 86 ms 13008 KB Output is correct
28 Correct 91 ms 13020 KB Output is correct
29 Correct 84 ms 12708 KB Output is correct
30 Correct 77 ms 12428 KB Output is correct
31 Correct 70 ms 11944 KB Output is correct
32 Correct 71 ms 12028 KB Output is correct
33 Correct 10 ms 1884 KB Output is correct
34 Correct 87 ms 13108 KB Output is correct
35 Correct 84 ms 12968 KB Output is correct
36 Correct 88 ms 13108 KB Output is correct
37 Correct 94 ms 12972 KB Output is correct
38 Correct 86 ms 12896 KB Output is correct
39 Correct 78 ms 12964 KB Output is correct
40 Correct 76 ms 13012 KB Output is correct
41 Correct 32 ms 5220 KB Output is correct
42 Correct 79 ms 11988 KB Output is correct
43 Correct 78 ms 13168 KB Output is correct
44 Correct 26 ms 5188 KB Output is correct
45 Correct 84 ms 13032 KB Output is correct
46 Correct 84 ms 13228 KB Output is correct
47 Correct 96 ms 13224 KB Output is correct
48 Correct 87 ms 13224 KB Output is correct