Submission #466300

# Submission time Handle Problem Language Result Execution time Memory
466300 2021-08-18T13:31:31 Z Namnamseo Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
838 ms 120080 KB
#include "rainbow.h"
#include <algorithm>
#include <vector>
#include <tuple>
#define x first
#define y second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define sort_and_unique(v) { sort(all(v)); v.erase(unique(all(v)), v.end()); }
using namespace std;
using pp=pair<int,int>;
using ll=long long;

const int maxm = int(1e5) + 10;

vector<pp> riv, eh, ev, e4;
void River(int sx, int sy, int m, char *s) {
	riv.resize(m+1);
	for (int i=0; i<m; ++i) {
		riv[i] = {sx, sy};
		if (s[i] == 'S') ++sx; else if (s[i] == 'N') --sx;
		else if (s[i] == 'E') ++sy; else --sy;
	}
	riv[m++] = {sx, sy};
	sort_and_unique(riv); m = riv.size();
	eh = riv; ev = riv; eh.resize(2*m); ev.resize(2*m);
	for (int i=0, x, y; i<m; ++i) { tie(x, y) = riv[i];
		eh[m+i] = {x, y-1}; ev[m+i] = {x-1, y};
	}
	sort_and_unique(eh); sort_and_unique(ev);
	e4 = riv; e4.resize(4*m);
	for (int i=0, j=m, x, y; i<m; ++i) { tie(x, y) = riv[i];
		e4[j++] = {x-1, y};
		e4[j++] = {x, y-1};
		e4[j++] = {x-1, y-1};
	}
	sort_and_unique(e4);
}

struct MST {
	const static int M = 262144;
	vector<int> t[M<<1];
	void put(int x, int y) { t[M+x].pb(y); }
	void init() {
		for (int i=0; i<M; ++i) sort(all(t[M+i]));
		for (int i=M-1; 1<=i; --i) {
			static int tmp[4*maxm];
			t[i] = vector<int>(tmp, merge(all(t[i*2]), all(t[i*2+1]), tmp));
		}
	}
	int rq(int l, int r, int d, int u) { if (d>u) return 0;
		int x = 0;
		auto vq = [&](const vector<int> &v) -> int {
			return upper_bound(all(v), u) - lower_bound(all(v), d);
		};
		for (l+=M, r+=M; l<=r; l/=2, r/=2) {
			if (l%2 == 1) x += vq(t[l++]);
			if (r%2 == 0) x += vq(t[r--]);
		}
		return x;
	}
} triv, teh, tev, te4;

void Write() {
#define wr(v, t) for (auto &tmp:v) t.put(tmp.x, tmp.y); t.init();
	wr(riv, triv);
	wr(eh, teh);
	wr(ev, tev);
	wr(e4, te4);
#undef wr
}

pp rmn, rmx;
void init(int R, int C, int sr, int sc, int M, char *S) {
	River(sr, sc, M, S);
	Write();
	rmn = {1e9, 1e9};
	rmx = {-1e9, -1e9};
	for (auto &tmp:riv) {
		rmn.x = min(rmn.x, tmp.x);
		rmn.y = min(rmn.y, tmp.y);
		rmx.x = max(rmx.x, tmp.x);
		rmx.y = max(rmx.y, tmp.y);
	}
}

int colour(int ar, int ac, int br, int bc) {
	ll w = br-ar+1, h = bc-ac+1;
	ll inv = w * h;
	ll ine = (w-1)*h + w*(h-1);
	ll inf = (w-1)*(h-1);

	inv -= triv.rq(ar, br, ac, bc);
	ine -= teh.rq(ar, br, ac, bc-1);
	ine -= tev.rq(ar, br-1, ac, bc);
	inf -= te4.rq(ar, br-1, ac, bc-1);

	if (ar < rmn.x && rmx.x < br &&
		ac < rmn.y && rmx.y < bc) ++inf;

    return inv - ine + inf;
}

# Verdict Execution time Memory Grader output
1 Correct 37 ms 49612 KB Output is correct
2 Correct 40 ms 49928 KB Output is correct
3 Correct 40 ms 49596 KB Output is correct
4 Correct 38 ms 49564 KB Output is correct
5 Correct 40 ms 49960 KB Output is correct
6 Correct 36 ms 49484 KB Output is correct
7 Correct 36 ms 49520 KB Output is correct
8 Correct 37 ms 49424 KB Output is correct
9 Correct 38 ms 49540 KB Output is correct
10 Correct 35 ms 49520 KB Output is correct
11 Correct 39 ms 49604 KB Output is correct
12 Correct 40 ms 49856 KB Output is correct
13 Correct 41 ms 50220 KB Output is correct
14 Correct 41 ms 50372 KB Output is correct
15 Correct 36 ms 49484 KB Output is correct
16 Correct 43 ms 49476 KB Output is correct
17 Correct 42 ms 49508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 49476 KB Output is correct
2 Correct 42 ms 49508 KB Output is correct
3 Correct 201 ms 81912 KB Output is correct
4 Correct 291 ms 103244 KB Output is correct
5 Correct 264 ms 102876 KB Output is correct
6 Correct 269 ms 91164 KB Output is correct
7 Correct 243 ms 90204 KB Output is correct
8 Correct 105 ms 51100 KB Output is correct
9 Correct 275 ms 103244 KB Output is correct
10 Correct 274 ms 102932 KB Output is correct
11 Correct 260 ms 91212 KB Output is correct
12 Correct 208 ms 99216 KB Output is correct
13 Correct 216 ms 103232 KB Output is correct
14 Correct 214 ms 102876 KB Output is correct
15 Correct 204 ms 91196 KB Output is correct
16 Correct 211 ms 87856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 49484 KB Output is correct
2 Correct 135 ms 102564 KB Output is correct
3 Correct 204 ms 119236 KB Output is correct
4 Correct 197 ms 108800 KB Output is correct
5 Correct 154 ms 97692 KB Output is correct
6 Correct 73 ms 60640 KB Output is correct
7 Correct 105 ms 70860 KB Output is correct
8 Correct 134 ms 97136 KB Output is correct
9 Correct 128 ms 91680 KB Output is correct
10 Correct 65 ms 60584 KB Output is correct
11 Correct 97 ms 76052 KB Output is correct
12 Correct 136 ms 102564 KB Output is correct
13 Correct 204 ms 119228 KB Output is correct
14 Correct 192 ms 108724 KB Output is correct
15 Correct 161 ms 97692 KB Output is correct
16 Correct 74 ms 58500 KB Output is correct
17 Correct 105 ms 70944 KB Output is correct
18 Correct 153 ms 102724 KB Output is correct
19 Correct 165 ms 110612 KB Output is correct
20 Correct 165 ms 110764 KB Output is correct
21 Correct 137 ms 97008 KB Output is correct
22 Correct 128 ms 91752 KB Output is correct
23 Correct 65 ms 60588 KB Output is correct
24 Correct 96 ms 76048 KB Output is correct
25 Correct 132 ms 102576 KB Output is correct
26 Correct 204 ms 119296 KB Output is correct
27 Correct 188 ms 108664 KB Output is correct
28 Correct 151 ms 97652 KB Output is correct
29 Correct 68 ms 58520 KB Output is correct
30 Correct 106 ms 70952 KB Output is correct
31 Correct 153 ms 102824 KB Output is correct
32 Correct 170 ms 110700 KB Output is correct
33 Correct 164 ms 110592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 49612 KB Output is correct
2 Correct 40 ms 49928 KB Output is correct
3 Correct 40 ms 49596 KB Output is correct
4 Correct 38 ms 49564 KB Output is correct
5 Correct 40 ms 49960 KB Output is correct
6 Correct 36 ms 49484 KB Output is correct
7 Correct 36 ms 49520 KB Output is correct
8 Correct 37 ms 49424 KB Output is correct
9 Correct 38 ms 49540 KB Output is correct
10 Correct 35 ms 49520 KB Output is correct
11 Correct 39 ms 49604 KB Output is correct
12 Correct 40 ms 49856 KB Output is correct
13 Correct 41 ms 50220 KB Output is correct
14 Correct 41 ms 50372 KB Output is correct
15 Correct 36 ms 49484 KB Output is correct
16 Correct 43 ms 49476 KB Output is correct
17 Correct 42 ms 49508 KB Output is correct
18 Correct 838 ms 77744 KB Output is correct
19 Correct 189 ms 51396 KB Output is correct
20 Correct 169 ms 50444 KB Output is correct
21 Correct 191 ms 50628 KB Output is correct
22 Correct 204 ms 50896 KB Output is correct
23 Correct 171 ms 51384 KB Output is correct
24 Correct 238 ms 50608 KB Output is correct
25 Correct 218 ms 50920 KB Output is correct
26 Correct 215 ms 51108 KB Output is correct
27 Correct 373 ms 73140 KB Output is correct
28 Correct 320 ms 61764 KB Output is correct
29 Correct 361 ms 71476 KB Output is correct
30 Correct 737 ms 103468 KB Output is correct
31 Correct 38 ms 49484 KB Output is correct
32 Correct 638 ms 73440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 49612 KB Output is correct
2 Correct 40 ms 49928 KB Output is correct
3 Correct 40 ms 49596 KB Output is correct
4 Correct 38 ms 49564 KB Output is correct
5 Correct 40 ms 49960 KB Output is correct
6 Correct 36 ms 49484 KB Output is correct
7 Correct 36 ms 49520 KB Output is correct
8 Correct 37 ms 49424 KB Output is correct
9 Correct 38 ms 49540 KB Output is correct
10 Correct 35 ms 49520 KB Output is correct
11 Correct 39 ms 49604 KB Output is correct
12 Correct 40 ms 49856 KB Output is correct
13 Correct 41 ms 50220 KB Output is correct
14 Correct 41 ms 50372 KB Output is correct
15 Correct 36 ms 49484 KB Output is correct
16 Correct 43 ms 49476 KB Output is correct
17 Correct 42 ms 49508 KB Output is correct
18 Correct 838 ms 77744 KB Output is correct
19 Correct 189 ms 51396 KB Output is correct
20 Correct 169 ms 50444 KB Output is correct
21 Correct 191 ms 50628 KB Output is correct
22 Correct 204 ms 50896 KB Output is correct
23 Correct 171 ms 51384 KB Output is correct
24 Correct 238 ms 50608 KB Output is correct
25 Correct 218 ms 50920 KB Output is correct
26 Correct 215 ms 51108 KB Output is correct
27 Correct 373 ms 73140 KB Output is correct
28 Correct 320 ms 61764 KB Output is correct
29 Correct 361 ms 71476 KB Output is correct
30 Correct 737 ms 103468 KB Output is correct
31 Correct 38 ms 49484 KB Output is correct
32 Correct 638 ms 73440 KB Output is correct
33 Correct 135 ms 102564 KB Output is correct
34 Correct 204 ms 119236 KB Output is correct
35 Correct 197 ms 108800 KB Output is correct
36 Correct 154 ms 97692 KB Output is correct
37 Correct 73 ms 60640 KB Output is correct
38 Correct 105 ms 70860 KB Output is correct
39 Correct 134 ms 97136 KB Output is correct
40 Correct 128 ms 91680 KB Output is correct
41 Correct 65 ms 60584 KB Output is correct
42 Correct 97 ms 76052 KB Output is correct
43 Correct 136 ms 102564 KB Output is correct
44 Correct 204 ms 119228 KB Output is correct
45 Correct 192 ms 108724 KB Output is correct
46 Correct 161 ms 97692 KB Output is correct
47 Correct 74 ms 58500 KB Output is correct
48 Correct 105 ms 70944 KB Output is correct
49 Correct 153 ms 102724 KB Output is correct
50 Correct 165 ms 110612 KB Output is correct
51 Correct 165 ms 110764 KB Output is correct
52 Correct 137 ms 97008 KB Output is correct
53 Correct 128 ms 91752 KB Output is correct
54 Correct 65 ms 60588 KB Output is correct
55 Correct 96 ms 76048 KB Output is correct
56 Correct 132 ms 102576 KB Output is correct
57 Correct 204 ms 119296 KB Output is correct
58 Correct 188 ms 108664 KB Output is correct
59 Correct 151 ms 97652 KB Output is correct
60 Correct 68 ms 58520 KB Output is correct
61 Correct 106 ms 70952 KB Output is correct
62 Correct 153 ms 102824 KB Output is correct
63 Correct 170 ms 110700 KB Output is correct
64 Correct 164 ms 110592 KB Output is correct
65 Correct 201 ms 81912 KB Output is correct
66 Correct 291 ms 103244 KB Output is correct
67 Correct 264 ms 102876 KB Output is correct
68 Correct 269 ms 91164 KB Output is correct
69 Correct 243 ms 90204 KB Output is correct
70 Correct 105 ms 51100 KB Output is correct
71 Correct 275 ms 103244 KB Output is correct
72 Correct 274 ms 102932 KB Output is correct
73 Correct 260 ms 91212 KB Output is correct
74 Correct 208 ms 99216 KB Output is correct
75 Correct 216 ms 103232 KB Output is correct
76 Correct 214 ms 102876 KB Output is correct
77 Correct 204 ms 91196 KB Output is correct
78 Correct 211 ms 87856 KB Output is correct
79 Correct 375 ms 97756 KB Output is correct
80 Correct 390 ms 92380 KB Output is correct
81 Correct 310 ms 61252 KB Output is correct
82 Correct 407 ms 76652 KB Output is correct
83 Correct 381 ms 103368 KB Output is correct
84 Correct 817 ms 120080 KB Output is correct
85 Correct 550 ms 109400 KB Output is correct
86 Correct 511 ms 98356 KB Output is correct
87 Correct 282 ms 59268 KB Output is correct
88 Correct 308 ms 71648 KB Output is correct
89 Correct 375 ms 103728 KB Output is correct
90 Correct 617 ms 111308 KB Output is correct
91 Correct 821 ms 111452 KB Output is correct