Submission #532552

# Submission time Handle Problem Language Result Execution time Memory
532552 2022-03-03T07:21:28 Z chenyan Snowball (JOI21_ho_t2) C++17
100 / 100
96 ms 18632 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<val.size()&&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:38:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    while(ind<val.size()&&val[ind].v<=rag[i][1]-rag[i][0]){
      |          ~~~^~~~~~~~~~~
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 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 440 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 440 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 472 KB Output is correct
20 Correct 29 ms 7024 KB Output is correct
21 Correct 28 ms 6936 KB Output is correct
22 Correct 29 ms 6624 KB Output is correct
23 Correct 27 ms 6656 KB Output is correct
24 Correct 31 ms 7444 KB Output is correct
25 Correct 90 ms 16696 KB Output is correct
26 Correct 86 ms 16608 KB Output is correct
27 Correct 94 ms 16184 KB Output is correct
28 Correct 85 ms 16436 KB Output is correct
29 Correct 88 ms 15912 KB Output is correct
30 Correct 72 ms 15272 KB Output is correct
31 Correct 69 ms 14760 KB Output is correct
32 Correct 67 ms 14912 KB Output is correct
33 Correct 10 ms 2000 KB Output is correct
34 Correct 96 ms 16936 KB Output is correct
35 Correct 84 ms 16360 KB Output is correct
36 Correct 89 ms 16676 KB Output is correct
37 Correct 86 ms 16400 KB Output is correct
38 Correct 90 ms 16280 KB Output is correct
39 Correct 81 ms 16372 KB Output is correct
40 Correct 78 ms 16544 KB Output is correct
41 Correct 30 ms 7612 KB Output is correct
42 Correct 77 ms 14880 KB Output is correct
43 Correct 80 ms 18176 KB Output is correct
44 Correct 31 ms 7504 KB Output is correct
45 Correct 85 ms 16352 KB Output is correct
46 Correct 91 ms 18236 KB Output is correct
47 Correct 88 ms 18432 KB Output is correct
48 Correct 92 ms 18632 KB Output is correct