Submission #870399

# Submission time Handle Problem Language Result Execution time Memory
870399 2023-11-07T16:55:57 Z aaron_dcoder Snowball (JOI21_ho_t2) C++17
100 / 100
223 ms 14408 KB
#define NDEBUG

#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)

#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)

#endif

#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
constexpr ll INFTY = 1e11;

struct snowscape {
	ll lsnowgone;
	ll rsnowgone;

	bool operator <(ll oth) const {
		return (lsnowgone+rsnowgone) < oth;
	}

	bool operator !=(const snowscape& oth) const {
		return pll{lsnowgone,rsnowgone} != pll{oth.lsnowgone,oth.rsnowgone};
	}


};

int main() {
	ll N,Q;
	cin >> N >> Q;

	vector<ll> X(N);
	vector<ll> W(Q);

	for (ll i = 0; i < N; ++i)
	{
		cin >> X[i];
	}
	for (ll i = 0; i < Q; ++i)
	{
		cin >> W[i];
	}

    snowscape curr = {0,0};
	vector<snowscape> landmarks = {curr,};
	ll cpos=0;
	for (ll wi : W)
	{
		cpos+=wi;
		curr.lsnowgone = max(curr.lsnowgone,cpos);
		curr.rsnowgone = max(curr.rsnowgone,-cpos);
		if (curr!=*landmarks.crbegin()) landmarks.push_back(curr);
	}

	vector<ll> outp(N);
	outp[0]+=landmarks.crbegin()->rsnowgone;
	outp[N-1]+=landmarks.crbegin()->lsnowgone;
	dbgv(landmarks.crbegin()->rsnowgone);
	for (ll i = 0; i < N-1; ++i)
	{
		auto lit = lower_bound(landmarks.cbegin(),landmarks.cend(),X[i+1]-X[i]);
		auto jb = lit-1;
		if (lit==landmarks.cend()) {
			outp[i] += jb->lsnowgone;
			outp[i+1] += jb->rsnowgone;
		}
		else {
			if (lit->lsnowgone > jb->lsnowgone) {
				outp[i] += (X[i+1]-X[i]) - jb->rsnowgone;
				outp[i+1] += jb->rsnowgone;
			}
			else {
				outp[i] += jb->lsnowgone;
				outp[i+1] +=  (X[i+1]-X[i]) - jb->lsnowgone;
			}
		}
	}

	for (ll o : outp)
	{
		cout << o << "\n";
	}




}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 2 ms 496 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 440 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 2 ms 496 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 440 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 67 ms 9632 KB Output is correct
21 Correct 63 ms 8644 KB Output is correct
22 Correct 57 ms 8384 KB Output is correct
23 Correct 54 ms 8384 KB Output is correct
24 Correct 59 ms 8132 KB Output is correct
25 Correct 153 ms 12816 KB Output is correct
26 Correct 152 ms 12728 KB Output is correct
27 Correct 147 ms 12432 KB Output is correct
28 Correct 151 ms 12472 KB Output is correct
29 Correct 143 ms 10692 KB Output is correct
30 Correct 120 ms 8528 KB Output is correct
31 Correct 109 ms 8024 KB Output is correct
32 Correct 110 ms 8148 KB Output is correct
33 Correct 16 ms 1740 KB Output is correct
34 Correct 144 ms 10096 KB Output is correct
35 Correct 141 ms 9932 KB Output is correct
36 Correct 158 ms 12824 KB Output is correct
37 Correct 152 ms 12620 KB Output is correct
38 Correct 146 ms 12220 KB Output is correct
39 Correct 154 ms 12488 KB Output is correct
40 Correct 132 ms 13500 KB Output is correct
41 Correct 77 ms 9232 KB Output is correct
42 Correct 110 ms 8260 KB Output is correct
43 Correct 223 ms 14012 KB Output is correct
44 Correct 76 ms 8896 KB Output is correct
45 Correct 138 ms 13428 KB Output is correct
46 Correct 162 ms 14268 KB Output is correct
47 Correct 178 ms 12484 KB Output is correct
48 Correct 166 ms 14408 KB Output is correct