Submission #554006

# Submission time Handle Problem Language Result Execution time Memory
554006 2022-04-27T14:28:57 Z hhhhaura Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
970 ms 622540 KB
#define wiwihorz
#include "rainbow.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define ll long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
#define x first
#define y second
namespace solver {
	int ii = 0, r, c;
	const int P = 50000000;
	struct node { int val, l, r; };
	vector<node> v(P, {0, 0, 0});
	vector<int> R, N, H, V;
	set<pii> vs, hs, nd, rv;
	int get_copy(int cur) {
		v[++ii] = v[cur];
		if(ii >= P) while(1);
		return ii;
	}
	void init_(int _r, int _c) {
		r = _r, c = _c;
		r+= 2, c += 2;
		R.assign(r + 1, 0);
		N.assign(r + 1, 0);
		H.assign(r + 1, 0);
		V.assign(c + 1, 0);
		R[0] = get_copy(0);
		N[0] = get_copy(0);
		H[0] = get_copy(0);
		V[0] = get_copy(0);
		vs.clear();
		hs.clear();
		nd.clear();
		rv.clear();
	}
	void modify(int L, int R, int pre, int cur, int id, int val) {
		if(L == R) v[cur].val += val;
		else {
			int mid = (L + R) / 2;
			if(id <= mid) {
				v[cur].l = get_copy(v[pre].l);
				modify(L, mid, v[pre].l, v[cur].l, id, val);
			}
			else {
				v[cur].r = get_copy(v[pre].r);
				modify(mid + 1, R, v[pre].r, v[cur].r, id, val);
			}
			v[cur].val = v[v[cur].l].val + v[v[cur].r].val;
		}

	}
	int query(int a, int b, int L, int R, int l, int r) {
		int mid = (L + R) / 2;
		if(r < L || l > R || (!a && !b)) return 0;
		if(l <= L && r >= R) return v[b].val - v[a].val;
		else return query(v[a].l, v[b].l, L, mid, l, r) + 
			query(v[a].r, v[b].r, mid + 1, R, l, r);
	}
	void add_position(int x, int y) {
		rv.insert({x, y});
		rep(i, 0, 1) rep(j, 0, 1) nd.insert({x + i, y + j});
		hs.insert({x + 1, y});
		hs.insert({x + 1, y + 1});
		vs.insert({y + 1, x});
		vs.insert({y + 1, x + 1});
	}
	void build_seg() {
		int pos = 0;
		for(auto i : rv) {
			rep(j, pos + 1, i.x) R[j] = get_copy(R[j - 1]);
			int cur = get_copy(R[i.x]);
			modify(1, c, R[i.x], cur, i.y, 1);
			R[i.x] = cur;
			pos = i.x;
		}
		rep(i, pos + 1, r) R[i] = get_copy(R[i - 1]);
		pos = 0;
		for(auto i : nd) {
			rep(j, pos + 1, i.x) N[j] = get_copy(N[j - 1]);
			int cur = get_copy(N[i.x]);
			modify(1, c, N[i.x], cur, i.y, 1);
			N[i.x] = cur;
			pos = i.x;
		}
		rep(i, pos + 1, r) N[i] = get_copy(N[i - 1]);
		pos = 0;
		for(auto i : hs) {
			rep(j, pos + 1, i.x) H[j] = get_copy(H[j - 1]);
			int cur = get_copy(H[i.x]);
			modify(1, c, H[i.x], cur, i.y, 1);
			H[i.x] = cur;
			pos = i.x;
		}
		rep(i, pos + 1, r) H[i] = get_copy(H[i - 1]);
		pos = 0;
		for(auto i : vs) {
			rep(j, pos + 1, i.x) V[j] = get_copy(V[j - 1]);
			int cur = get_copy(V[i.x]);
			modify(1, r, V[i.x], cur, i.y, 1);
			V[i.x] = cur;
			pos = i.x;
		}
		rep(i, pos + 1, c) V[i] = get_copy(V[i - 1]);
	}
};
using namespace solver;
void init(int r, int c, int sr, int sc, int M, char *S) {
	init_(r, c);
	int x = sr, y = sc;
	add_position(x, y);
	rep(i, 0, M - 1) {
		if(S[i] == 'W') y -= 1;
		else if(S[i] == 'E') y += 1;
		else if(S[i] == 'N') x -= 1;
		else x += 1;
		add_position(x, y);
	}
	build_seg();
	return;
}
int colour(int ar, int ac, int br, int bc) {
    int rr = query(R[ar - 1], R[br], 1, c, ac, bc);
	int vv = query(N[ar], N[br], 1, c, ac + 1, bc)
		+ (br - ar + 2) * 2 + (bc - ac + 2) * 2 - 4;
	int ee = query(H[ar], H[br + 1], 1, c, ac + 1, bc)
		+ query(V[ac], V[bc + 1], 1, r, ar + 1, br) 
		+ (br - ar + 1) * 2 + (bc - ac + 1) * 2;
	int yes = query(R[ar - 1], R[ar], 1, c, ac, bc) 
		+ query(R[br - 1], R[br], 1, c, ac, bc)
		+ query(R[ar - 1], R[br], 1, c, ac, ac)
		+ query(R[ar - 1], R[br], 1, c, bc, bc);
	int ans = ee - vv + 2 - bool(yes || !rr) - rr;
	return ans;
}

Compilation message

rainbow.cpp:6: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    6 | #pragma loop-opt(on)
      | 
rainbow.cpp:21:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   21 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |             ^~~~
rainbow.cpp:21:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   21 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 246 ms 587304 KB Output is correct
2 Correct 245 ms 587596 KB Output is correct
3 Correct 244 ms 587412 KB Output is correct
4 Correct 252 ms 587460 KB Output is correct
5 Correct 250 ms 587572 KB Output is correct
6 Correct 255 ms 587456 KB Output is correct
7 Correct 249 ms 587340 KB Output is correct
8 Correct 249 ms 587308 KB Output is correct
9 Correct 246 ms 587364 KB Output is correct
10 Correct 257 ms 587304 KB Output is correct
11 Correct 251 ms 587428 KB Output is correct
12 Correct 248 ms 587520 KB Output is correct
13 Correct 248 ms 587640 KB Output is correct
14 Correct 248 ms 587824 KB Output is correct
15 Correct 251 ms 587336 KB Output is correct
16 Correct 244 ms 587272 KB Output is correct
17 Correct 248 ms 587324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 587272 KB Output is correct
2 Correct 248 ms 587324 KB Output is correct
3 Correct 576 ms 605620 KB Output is correct
4 Correct 730 ms 619776 KB Output is correct
5 Correct 733 ms 620040 KB Output is correct
6 Correct 645 ms 613468 KB Output is correct
7 Correct 732 ms 612940 KB Output is correct
8 Correct 326 ms 591820 KB Output is correct
9 Correct 726 ms 619988 KB Output is correct
10 Correct 762 ms 619784 KB Output is correct
11 Correct 675 ms 613268 KB Output is correct
12 Correct 562 ms 617840 KB Output is correct
13 Correct 566 ms 619856 KB Output is correct
14 Correct 595 ms 619868 KB Output is correct
15 Correct 575 ms 613324 KB Output is correct
16 Correct 623 ms 611612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 587336 KB Output is correct
2 Correct 558 ms 618756 KB Output is correct
3 Correct 550 ms 618828 KB Output is correct
4 Correct 560 ms 618828 KB Output is correct
5 Correct 481 ms 611800 KB Output is correct
6 Correct 348 ms 595964 KB Output is correct
7 Correct 422 ms 601184 KB Output is correct
8 Correct 557 ms 612940 KB Output is correct
9 Correct 582 ms 609900 KB Output is correct
10 Correct 418 ms 594124 KB Output is correct
11 Correct 443 ms 602716 KB Output is correct
12 Correct 558 ms 618828 KB Output is correct
13 Correct 561 ms 618972 KB Output is correct
14 Correct 574 ms 618952 KB Output is correct
15 Correct 476 ms 611732 KB Output is correct
16 Correct 349 ms 594812 KB Output is correct
17 Correct 418 ms 601244 KB Output is correct
18 Correct 542 ms 618896 KB Output is correct
19 Correct 540 ms 618844 KB Output is correct
20 Correct 543 ms 618788 KB Output is correct
21 Correct 484 ms 612964 KB Output is correct
22 Correct 496 ms 609980 KB Output is correct
23 Correct 345 ms 594144 KB Output is correct
24 Correct 436 ms 602616 KB Output is correct
25 Correct 557 ms 618896 KB Output is correct
26 Correct 539 ms 618828 KB Output is correct
27 Correct 549 ms 618788 KB Output is correct
28 Correct 474 ms 611840 KB Output is correct
29 Correct 344 ms 594936 KB Output is correct
30 Correct 412 ms 601212 KB Output is correct
31 Correct 527 ms 618788 KB Output is correct
32 Correct 547 ms 618888 KB Output is correct
33 Correct 541 ms 618836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 587304 KB Output is correct
2 Correct 245 ms 587596 KB Output is correct
3 Correct 244 ms 587412 KB Output is correct
4 Correct 252 ms 587460 KB Output is correct
5 Correct 250 ms 587572 KB Output is correct
6 Correct 255 ms 587456 KB Output is correct
7 Correct 249 ms 587340 KB Output is correct
8 Correct 249 ms 587308 KB Output is correct
9 Correct 246 ms 587364 KB Output is correct
10 Correct 257 ms 587304 KB Output is correct
11 Correct 251 ms 587428 KB Output is correct
12 Correct 248 ms 587520 KB Output is correct
13 Correct 248 ms 587640 KB Output is correct
14 Correct 248 ms 587824 KB Output is correct
15 Correct 251 ms 587336 KB Output is correct
16 Correct 244 ms 587272 KB Output is correct
17 Correct 248 ms 587324 KB Output is correct
18 Correct 779 ms 602564 KB Output is correct
19 Correct 412 ms 588808 KB Output is correct
20 Correct 374 ms 588080 KB Output is correct
21 Correct 380 ms 588372 KB Output is correct
22 Correct 410 ms 588348 KB Output is correct
23 Correct 411 ms 588776 KB Output is correct
24 Correct 373 ms 588364 KB Output is correct
25 Correct 390 ms 588380 KB Output is correct
26 Correct 443 ms 588488 KB Output is correct
27 Correct 526 ms 599776 KB Output is correct
28 Correct 457 ms 593688 KB Output is correct
29 Correct 554 ms 598732 KB Output is correct
30 Correct 681 ms 616452 KB Output is correct
31 Correct 251 ms 587412 KB Output is correct
32 Correct 667 ms 599748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 587304 KB Output is correct
2 Correct 245 ms 587596 KB Output is correct
3 Correct 244 ms 587412 KB Output is correct
4 Correct 252 ms 587460 KB Output is correct
5 Correct 250 ms 587572 KB Output is correct
6 Correct 255 ms 587456 KB Output is correct
7 Correct 249 ms 587340 KB Output is correct
8 Correct 249 ms 587308 KB Output is correct
9 Correct 246 ms 587364 KB Output is correct
10 Correct 257 ms 587304 KB Output is correct
11 Correct 251 ms 587428 KB Output is correct
12 Correct 248 ms 587520 KB Output is correct
13 Correct 248 ms 587640 KB Output is correct
14 Correct 248 ms 587824 KB Output is correct
15 Correct 251 ms 587336 KB Output is correct
16 Correct 244 ms 587272 KB Output is correct
17 Correct 248 ms 587324 KB Output is correct
18 Correct 779 ms 602564 KB Output is correct
19 Correct 412 ms 588808 KB Output is correct
20 Correct 374 ms 588080 KB Output is correct
21 Correct 380 ms 588372 KB Output is correct
22 Correct 410 ms 588348 KB Output is correct
23 Correct 411 ms 588776 KB Output is correct
24 Correct 373 ms 588364 KB Output is correct
25 Correct 390 ms 588380 KB Output is correct
26 Correct 443 ms 588488 KB Output is correct
27 Correct 526 ms 599776 KB Output is correct
28 Correct 457 ms 593688 KB Output is correct
29 Correct 554 ms 598732 KB Output is correct
30 Correct 681 ms 616452 KB Output is correct
31 Correct 251 ms 587412 KB Output is correct
32 Correct 667 ms 599748 KB Output is correct
33 Correct 558 ms 618756 KB Output is correct
34 Correct 550 ms 618828 KB Output is correct
35 Correct 560 ms 618828 KB Output is correct
36 Correct 481 ms 611800 KB Output is correct
37 Correct 348 ms 595964 KB Output is correct
38 Correct 422 ms 601184 KB Output is correct
39 Correct 557 ms 612940 KB Output is correct
40 Correct 582 ms 609900 KB Output is correct
41 Correct 418 ms 594124 KB Output is correct
42 Correct 443 ms 602716 KB Output is correct
43 Correct 558 ms 618828 KB Output is correct
44 Correct 561 ms 618972 KB Output is correct
45 Correct 574 ms 618952 KB Output is correct
46 Correct 476 ms 611732 KB Output is correct
47 Correct 349 ms 594812 KB Output is correct
48 Correct 418 ms 601244 KB Output is correct
49 Correct 542 ms 618896 KB Output is correct
50 Correct 540 ms 618844 KB Output is correct
51 Correct 543 ms 618788 KB Output is correct
52 Correct 484 ms 612964 KB Output is correct
53 Correct 496 ms 609980 KB Output is correct
54 Correct 345 ms 594144 KB Output is correct
55 Correct 436 ms 602616 KB Output is correct
56 Correct 557 ms 618896 KB Output is correct
57 Correct 539 ms 618828 KB Output is correct
58 Correct 549 ms 618788 KB Output is correct
59 Correct 474 ms 611840 KB Output is correct
60 Correct 344 ms 594936 KB Output is correct
61 Correct 412 ms 601212 KB Output is correct
62 Correct 527 ms 618788 KB Output is correct
63 Correct 547 ms 618888 KB Output is correct
64 Correct 541 ms 618836 KB Output is correct
65 Correct 576 ms 605620 KB Output is correct
66 Correct 730 ms 619776 KB Output is correct
67 Correct 733 ms 620040 KB Output is correct
68 Correct 645 ms 613468 KB Output is correct
69 Correct 732 ms 612940 KB Output is correct
70 Correct 326 ms 591820 KB Output is correct
71 Correct 726 ms 619988 KB Output is correct
72 Correct 762 ms 619784 KB Output is correct
73 Correct 675 ms 613268 KB Output is correct
74 Correct 562 ms 617840 KB Output is correct
75 Correct 566 ms 619856 KB Output is correct
76 Correct 595 ms 619868 KB Output is correct
77 Correct 575 ms 613324 KB Output is correct
78 Correct 623 ms 611612 KB Output is correct
79 Correct 930 ms 616316 KB Output is correct
80 Correct 970 ms 613444 KB Output is correct
81 Correct 551 ms 597580 KB Output is correct
82 Correct 654 ms 606124 KB Output is correct
83 Correct 824 ms 622464 KB Output is correct
84 Correct 712 ms 622384 KB Output is correct
85 Correct 755 ms 622384 KB Output is correct
86 Correct 650 ms 615284 KB Output is correct
87 Correct 458 ms 598352 KB Output is correct
88 Correct 538 ms 604800 KB Output is correct
89 Correct 765 ms 622540 KB Output is correct
90 Correct 810 ms 622412 KB Output is correct
91 Correct 843 ms 622460 KB Output is correct