답안 #371265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371265 2021-02-26T10:12:27 Z arnold518 Snowball (JOI21_ho_t2) C++14
100 / 100
136 ms 11500 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int N, Q;
ll A[MAXN+10], B[MAXN+10];
ll C[MAXN+10], D[MAXN+10], E[MAXN+10];
ll ans[MAXN+10];

int main()
{
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
	for(int i=1; i<=Q; i++) scanf("%lld", &B[i]);

	ll now=0;
	for(int i=1; i<=Q; i++)
	{
		now+=B[i];
		E[i]=now;
		C[i]=min(C[i-1], now);
		D[i]=max(D[i-1], now);
	}

	for(int i=1; i<N; i++)
	{
		ll d=A[i+1]-A[i];


		int lo=0, hi=Q+1;
		while(lo+1<hi)
		{
			int mid=lo+hi>>1;
			if(D[mid]-C[mid]<=d) lo=mid;
			else hi=mid;
		}
		if(lo==Q)
		{
			ans[i]+=D[Q];
			ans[i+1]-=C[Q];
		}
		else
		{
			if(C[lo]==C[hi])
			{
				ans[i+1]-=C[lo];
				ans[i]+=d+C[lo];
			}
			else
			{
				ans[i]+=D[lo];
				ans[i+1]+=d-D[lo];
			}
		}
	}
	ans[1]-=C[Q];
	ans[N]+=D[Q];
	for(int i=1; i<=N; i++) printf("%lld\n", ans[i]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |    int mid=lo+hi>>1;
      |            ~~^~~
Main.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d%d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:18:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
Main.cpp:19:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  for(int i=1; i<=Q; i++) scanf("%lld", &B[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 36 ms 6656 KB Output is correct
21 Correct 35 ms 6636 KB Output is correct
22 Correct 33 ms 6636 KB Output is correct
23 Correct 33 ms 6636 KB Output is correct
24 Correct 41 ms 7020 KB Output is correct
25 Correct 136 ms 11372 KB Output is correct
26 Correct 124 ms 11260 KB Output is correct
27 Correct 121 ms 11244 KB Output is correct
28 Correct 128 ms 11116 KB Output is correct
29 Correct 123 ms 11116 KB Output is correct
30 Correct 118 ms 10476 KB Output is correct
31 Correct 88 ms 10092 KB Output is correct
32 Correct 79 ms 10092 KB Output is correct
33 Correct 12 ms 1516 KB Output is correct
34 Correct 128 ms 11372 KB Output is correct
35 Correct 122 ms 11116 KB Output is correct
36 Correct 124 ms 11372 KB Output is correct
37 Correct 125 ms 11244 KB Output is correct
38 Correct 121 ms 11116 KB Output is correct
39 Correct 124 ms 11116 KB Output is correct
40 Correct 116 ms 11116 KB Output is correct
41 Correct 38 ms 6636 KB Output is correct
42 Correct 79 ms 10092 KB Output is correct
43 Correct 103 ms 11416 KB Output is correct
44 Correct 38 ms 6636 KB Output is correct
45 Correct 87 ms 11116 KB Output is correct
46 Correct 105 ms 11372 KB Output is correct
47 Correct 106 ms 11500 KB Output is correct
48 Correct 107 ms 11448 KB Output is correct