답안 #413008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413008 2021-05-28T02:39:56 Z joseacaz Snowball (JOI21_ho_t2) C++17
100 / 100
144 ms 17732 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
 
const int MAXN = (int)2e5 + 5;
const ll INF = (1LL << 62LL);
int N, Q;
ll a[MAXN], W[MAXN];
pair<ll, int> spacesL[MAXN], spacesR[MAXN];
 
ll l[MAXN], r[MAXN], pos;
ll finalL[MAXN], finalR[MAXN];
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> Q;
	for(int i = 1; i <= N; i++)
		cin >> a[i];
	a[0] = -INF, a[N + 1] = INF;
	for(int i = 0; i <= N + 1; i++)
	{
		if(i < N + 1)
			spacesR[i] = {a[i + 1] - a[i], i};
		else
			spacesR[i] = {0, N + 1};
			
		if(i > 0)
			spacesL[i] = {a[i] - a[i - 1], i};
		else
			spacesL[i] = {0, 0};
	}
	sort(spacesR, spacesR + N + 2);
	sort(spacesL, spacesL + N + 2);
	
	ll delta = 0;
	int lpnt = 0, rpnt = 0;
	for(int q = 1; q <= Q; q++)
	{
		cin >> W[q];
		pos += W[q];
		l[q] = min(l[q - 1], pos);
		r[q] = max(r[q - 1], pos);
		
      	if(l[q] < l[q - 1])
      		delta += l[q - 1] - l[q];
      	if(r[q - 1] < r[q])
          	delta += r[q] - r[q - 1];
		if(l[q] < l[q - 1] || r[q - 1] < r[q])
		{
			for(; lpnt <= N + 1; lpnt++)
			{
				if(spacesL[lpnt].second == 0)
					continue;
				if(spacesL[lpnt].first > delta)
					break;
				int idx = spacesL[lpnt].second;
				finalL[idx] = a[idx] + l[q - 1];
              	if(l[q] < l[q - 1])
                  	finalL[idx] -= (spacesL[lpnt].first - (delta - l[q - 1] + l[q]));
			}
			
			for(; rpnt <= N + 1; rpnt++)
			{
				if(spacesR[rpnt].second == N + 1)
					continue;
				if(spacesR[rpnt].first > delta)
					break;
				int idx = spacesR[rpnt].second;
				finalR[idx] = a[idx] + r[q - 1];
              	if(r[q] > r[q - 1])
                  	finalR[idx] += (spacesR[rpnt].first - (delta - r[q] + r[q - 1]));
			}
		}
	}
	
	for(int i = lpnt; i <= N + 1; i++)
	{
		int idx = spacesL[i].second;
		finalL[idx] = a[idx] + l[Q];
	}
	for(int i = rpnt; i <= N + 1; i++)
	{
		int idx = spacesR[i].second;
		finalR[idx] = a[idx] + r[Q];
	}
	
	for(int i = 1; i <= N; i++)
		cout << finalR[i] - finalL[i] << "\n";
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:61:8: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   61 |        if(r[q - 1] < r[q])
      |        ^~
Main.cpp:63:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   63 |   if(l[q] < l[q - 1] || r[q - 1] < r[q])
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 35 ms 4984 KB Output is correct
21 Correct 34 ms 4984 KB Output is correct
22 Correct 34 ms 5048 KB Output is correct
23 Correct 33 ms 5060 KB Output is correct
24 Correct 40 ms 6460 KB Output is correct
25 Correct 144 ms 17628 KB Output is correct
26 Correct 125 ms 17620 KB Output is correct
27 Correct 125 ms 17476 KB Output is correct
28 Correct 126 ms 17400 KB Output is correct
29 Correct 128 ms 17360 KB Output is correct
30 Correct 121 ms 16796 KB Output is correct
31 Correct 117 ms 16480 KB Output is correct
32 Correct 82 ms 16452 KB Output is correct
33 Correct 13 ms 2044 KB Output is correct
34 Correct 130 ms 17564 KB Output is correct
35 Correct 139 ms 17476 KB Output is correct
36 Correct 125 ms 17680 KB Output is correct
37 Correct 120 ms 17404 KB Output is correct
38 Correct 129 ms 17476 KB Output is correct
39 Correct 127 ms 17372 KB Output is correct
40 Correct 126 ms 17504 KB Output is correct
41 Correct 36 ms 5068 KB Output is correct
42 Correct 108 ms 16356 KB Output is correct
43 Correct 117 ms 17632 KB Output is correct
44 Correct 37 ms 5088 KB Output is correct
45 Correct 115 ms 17384 KB Output is correct
46 Correct 124 ms 17712 KB Output is correct
47 Correct 114 ms 17732 KB Output is correct
48 Correct 116 ms 17712 KB Output is correct