답안 #543404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543404 2022-03-30T13:27:57 Z amunduzbaev 무지개나라 (APIO17_rainbow) C++17
100 / 100
2065 ms 235880 KB
#include "rainbow.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif

#define int long long 
#define i32 int32_t
#define ar array
const int N = 2e5 + 5;

struct MSST{
	vector<int> tree[N << 2];
	void add(int i, int y, int lx = 0, int rx = N, int x = 1){
		tree[x].push_back(y);
		if(lx == rx) return;
		int m = (lx + rx) >> 1;
		if(i <= m) add(i, y, lx, m, x<<1);
		else add(i, y, m+1, rx, x<<1|1);
	}
	
	void build(int lx = 0, int rx = N, int x = 1){
		sort(tree[x].begin(), tree[x].end());
		if(lx == rx) return;
		int m = (lx + rx) >> 1;
		build(lx, m, x<<1), build(m+1, rx, x<<1|1);
	}
	
	int get(int l, int r, int l_, int r_, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return 0;
		if(lx >= l && rx <= r){
			auto R = upper_bound(tree[x].begin(), tree[x].end(), r_);
			auto L = lower_bound(tree[x].begin(), tree[x].end(), l_);
			return R - L;
		} int m = (lx + rx) >> 1;
		return get(l, r, l_, r_, lx, m, x<<1) + get(l, r, l_, r_, m+1, rx, x<<1|1);
	}
}ed[2], ver, sq; //, ver, sq;
set<ar<int, 2>> ss, tot, is[2];
int Lx, Rx, Ly, Ry;

void init(i32 n, i32 m, i32 x, i32 y, i32 k, char *s) {
	ss.insert({x, y});
	Lx = Rx = x, Ly = Ry = y;
	for(int i=0;i<k;i++){
		if(s[i] == 'N') x--;
		if(s[i] == 'S') x++;
		if(s[i] == 'W') y--;
		if(s[i] == 'E') y++;
		ss.insert({x, y});
		Lx = min(Lx, 1ll * x);
		Rx = max(Rx, 1ll * x);
		Ly = min(Ly, 1ll * y);
		Ry = max(Ry, 1ll * y);
	}
	
	for(auto x : ss){
		//~ cout<<x[0]<<" "<<x[1]<<"\n";
		is[0].insert(x);
		is[0].insert({x[0] + 1, x[1]});
		is[1].insert(x);
		is[1].insert({x[0], x[1] + 1});
		tot.insert(x);
		tot.insert({x[0] + 1, x[1]});
		tot.insert({x[0], x[1] + 1});
		tot.insert({x[0] + 1, x[1] + 1});
		sq.add(x[0], x[1]);
	}
	
	for(auto x : tot){
		if(is[0].count(x)) ed[0].add(x[0], x[1]);
		if(is[1].count(x)) ed[1].add(x[0], x[1]);
		ver.add(x[0], x[1]);
	}
	
	ed[0].build();
	ed[1].build();
	ver.build();
	sq.build();
}

/*

6 4 9 4
3 3
NWESSWEWS
2 3 2 3
3 2 4 4
5 3 6 4
1 2 5 3

13 13 13 1
6 8
WWWEENWEEWEWE
3 4 10 13

13 13 26 1
5 9
SEWSWEENSNSNSEENSNSNNNWWSN
1 5 8 13

*/

i32 colour(i32 lx, i32 ly, i32 rx, i32 ry) {
	if(lx > rx) swap(lx, rx);
	if(ly > ry) swap(ly, ry);
	int ee = ed[0].get(lx, rx + 1, ly, ry);
	ee += ed[1].get(lx, rx, ly, ry + 1);
	int V = ver.get(lx, rx + 1, ly, ry + 1);
	int tmp = 0, tt = 0;
	tmp += ver.get(lx, lx, ly, ry + 1);
	tt += ed[0].get(lx, lx, ly, ry);
	
	tmp += ver.get(rx + 1, rx + 1, ly, ry + 1);
	tt += ed[0].get(rx + 1, rx + 1, ly, ry);
	
	if(lx < rx) tmp += ver.get(lx + 1, rx, ly, ly);
	tt += ed[1].get(lx, rx, ly, ly);
	
	if(lx < rx) tmp += ver.get(lx + 1, rx, ry + 1, ry + 1);
	tt += ed[1].get(lx, rx, ry + 1, ry + 1);
	
	int v = (rx - lx + ry - ly + 2) * 2;
	V += (v - tmp);
	ee += (v - tt);
	//~ cout<<tmp<<" "<<tt<<"\n";
	int F = sq.get(lx, rx, ly, ry);
	//~ assert(1 - V + ee - F >= 0);
	int res = (1 - V + ee - F);
	if(lx < Lx && Rx < rx && ly < Ly && Ry < ry){
		res++;
	}
	return res;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 75760 KB Output is correct
2 Correct 52 ms 76852 KB Output is correct
3 Correct 47 ms 75884 KB Output is correct
4 Correct 47 ms 75776 KB Output is correct
5 Correct 52 ms 76936 KB Output is correct
6 Correct 45 ms 75404 KB Output is correct
7 Correct 40 ms 75344 KB Output is correct
8 Correct 41 ms 75444 KB Output is correct
9 Correct 40 ms 75432 KB Output is correct
10 Correct 38 ms 75416 KB Output is correct
11 Correct 50 ms 75948 KB Output is correct
12 Correct 46 ms 76264 KB Output is correct
13 Correct 52 ms 77372 KB Output is correct
14 Correct 58 ms 78020 KB Output is correct
15 Correct 43 ms 75520 KB Output is correct
16 Correct 45 ms 75420 KB Output is correct
17 Correct 41 ms 75332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 75420 KB Output is correct
2 Correct 41 ms 75332 KB Output is correct
3 Correct 935 ms 155772 KB Output is correct
4 Correct 1395 ms 215728 KB Output is correct
5 Correct 1468 ms 213124 KB Output is correct
6 Correct 1105 ms 189048 KB Output is correct
7 Correct 1125 ms 180112 KB Output is correct
8 Correct 279 ms 76668 KB Output is correct
9 Correct 1320 ms 215416 KB Output is correct
10 Correct 1352 ms 212776 KB Output is correct
11 Correct 1094 ms 186528 KB Output is correct
12 Correct 1255 ms 206708 KB Output is correct
13 Correct 1142 ms 213684 KB Output is correct
14 Correct 1120 ms 211936 KB Output is correct
15 Correct 990 ms 188144 KB Output is correct
16 Correct 1016 ms 182344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 75520 KB Output is correct
2 Correct 1218 ms 213848 KB Output is correct
3 Correct 681 ms 232236 KB Output is correct
4 Correct 688 ms 231960 KB Output is correct
5 Correct 645 ms 187784 KB Output is correct
6 Correct 170 ms 102348 KB Output is correct
7 Correct 341 ms 127860 KB Output is correct
8 Correct 767 ms 198924 KB Output is correct
9 Correct 685 ms 189284 KB Output is correct
10 Correct 210 ms 103912 KB Output is correct
11 Correct 440 ms 147548 KB Output is correct
12 Correct 1298 ms 213896 KB Output is correct
13 Correct 700 ms 232384 KB Output is correct
14 Correct 779 ms 232180 KB Output is correct
15 Correct 634 ms 187980 KB Output is correct
16 Correct 153 ms 97188 KB Output is correct
17 Correct 330 ms 128772 KB Output is correct
18 Correct 759 ms 216688 KB Output is correct
19 Correct 888 ms 227860 KB Output is correct
20 Correct 903 ms 227748 KB Output is correct
21 Correct 772 ms 198836 KB Output is correct
22 Correct 688 ms 189284 KB Output is correct
23 Correct 211 ms 103916 KB Output is correct
24 Correct 444 ms 147644 KB Output is correct
25 Correct 1219 ms 213908 KB Output is correct
26 Correct 701 ms 232240 KB Output is correct
27 Correct 698 ms 232184 KB Output is correct
28 Correct 676 ms 188040 KB Output is correct
29 Correct 162 ms 97272 KB Output is correct
30 Correct 308 ms 128836 KB Output is correct
31 Correct 765 ms 216664 KB Output is correct
32 Correct 880 ms 227892 KB Output is correct
33 Correct 873 ms 227712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 75760 KB Output is correct
2 Correct 52 ms 76852 KB Output is correct
3 Correct 47 ms 75884 KB Output is correct
4 Correct 47 ms 75776 KB Output is correct
5 Correct 52 ms 76936 KB Output is correct
6 Correct 45 ms 75404 KB Output is correct
7 Correct 40 ms 75344 KB Output is correct
8 Correct 41 ms 75444 KB Output is correct
9 Correct 40 ms 75432 KB Output is correct
10 Correct 38 ms 75416 KB Output is correct
11 Correct 50 ms 75948 KB Output is correct
12 Correct 46 ms 76264 KB Output is correct
13 Correct 52 ms 77372 KB Output is correct
14 Correct 58 ms 78020 KB Output is correct
15 Correct 43 ms 75520 KB Output is correct
16 Correct 45 ms 75420 KB Output is correct
17 Correct 41 ms 75332 KB Output is correct
18 Correct 2065 ms 153500 KB Output is correct
19 Correct 438 ms 82508 KB Output is correct
20 Correct 412 ms 79556 KB Output is correct
21 Correct 410 ms 80172 KB Output is correct
22 Correct 470 ms 80896 KB Output is correct
23 Correct 387 ms 82436 KB Output is correct
24 Correct 542 ms 79892 KB Output is correct
25 Correct 483 ms 80664 KB Output is correct
26 Correct 499 ms 81376 KB Output is correct
27 Correct 1012 ms 137624 KB Output is correct
28 Correct 811 ms 106552 KB Output is correct
29 Correct 1091 ms 131000 KB Output is correct
30 Correct 1925 ms 220084 KB Output is correct
31 Correct 56 ms 75592 KB Output is correct
32 Correct 1519 ms 140444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 75760 KB Output is correct
2 Correct 52 ms 76852 KB Output is correct
3 Correct 47 ms 75884 KB Output is correct
4 Correct 47 ms 75776 KB Output is correct
5 Correct 52 ms 76936 KB Output is correct
6 Correct 45 ms 75404 KB Output is correct
7 Correct 40 ms 75344 KB Output is correct
8 Correct 41 ms 75444 KB Output is correct
9 Correct 40 ms 75432 KB Output is correct
10 Correct 38 ms 75416 KB Output is correct
11 Correct 50 ms 75948 KB Output is correct
12 Correct 46 ms 76264 KB Output is correct
13 Correct 52 ms 77372 KB Output is correct
14 Correct 58 ms 78020 KB Output is correct
15 Correct 43 ms 75520 KB Output is correct
16 Correct 45 ms 75420 KB Output is correct
17 Correct 41 ms 75332 KB Output is correct
18 Correct 2065 ms 153500 KB Output is correct
19 Correct 438 ms 82508 KB Output is correct
20 Correct 412 ms 79556 KB Output is correct
21 Correct 410 ms 80172 KB Output is correct
22 Correct 470 ms 80896 KB Output is correct
23 Correct 387 ms 82436 KB Output is correct
24 Correct 542 ms 79892 KB Output is correct
25 Correct 483 ms 80664 KB Output is correct
26 Correct 499 ms 81376 KB Output is correct
27 Correct 1012 ms 137624 KB Output is correct
28 Correct 811 ms 106552 KB Output is correct
29 Correct 1091 ms 131000 KB Output is correct
30 Correct 1925 ms 220084 KB Output is correct
31 Correct 56 ms 75592 KB Output is correct
32 Correct 1519 ms 140444 KB Output is correct
33 Correct 1218 ms 213848 KB Output is correct
34 Correct 681 ms 232236 KB Output is correct
35 Correct 688 ms 231960 KB Output is correct
36 Correct 645 ms 187784 KB Output is correct
37 Correct 170 ms 102348 KB Output is correct
38 Correct 341 ms 127860 KB Output is correct
39 Correct 767 ms 198924 KB Output is correct
40 Correct 685 ms 189284 KB Output is correct
41 Correct 210 ms 103912 KB Output is correct
42 Correct 440 ms 147548 KB Output is correct
43 Correct 1298 ms 213896 KB Output is correct
44 Correct 700 ms 232384 KB Output is correct
45 Correct 779 ms 232180 KB Output is correct
46 Correct 634 ms 187980 KB Output is correct
47 Correct 153 ms 97188 KB Output is correct
48 Correct 330 ms 128772 KB Output is correct
49 Correct 759 ms 216688 KB Output is correct
50 Correct 888 ms 227860 KB Output is correct
51 Correct 903 ms 227748 KB Output is correct
52 Correct 772 ms 198836 KB Output is correct
53 Correct 688 ms 189284 KB Output is correct
54 Correct 211 ms 103916 KB Output is correct
55 Correct 444 ms 147644 KB Output is correct
56 Correct 1219 ms 213908 KB Output is correct
57 Correct 701 ms 232240 KB Output is correct
58 Correct 698 ms 232184 KB Output is correct
59 Correct 676 ms 188040 KB Output is correct
60 Correct 162 ms 97272 KB Output is correct
61 Correct 308 ms 128836 KB Output is correct
62 Correct 765 ms 216664 KB Output is correct
63 Correct 880 ms 227892 KB Output is correct
64 Correct 873 ms 227712 KB Output is correct
65 Correct 935 ms 155772 KB Output is correct
66 Correct 1395 ms 215728 KB Output is correct
67 Correct 1468 ms 213124 KB Output is correct
68 Correct 1105 ms 189048 KB Output is correct
69 Correct 1125 ms 180112 KB Output is correct
70 Correct 279 ms 76668 KB Output is correct
71 Correct 1320 ms 215416 KB Output is correct
72 Correct 1352 ms 212776 KB Output is correct
73 Correct 1094 ms 186528 KB Output is correct
74 Correct 1255 ms 206708 KB Output is correct
75 Correct 1142 ms 213684 KB Output is correct
76 Correct 1120 ms 211936 KB Output is correct
77 Correct 990 ms 188144 KB Output is correct
78 Correct 1016 ms 182344 KB Output is correct
79 Correct 1422 ms 202264 KB Output is correct
80 Correct 1375 ms 192808 KB Output is correct
81 Correct 815 ms 107396 KB Output is correct
82 Correct 1135 ms 151056 KB Output is correct
83 Correct 1824 ms 217320 KB Output is correct
84 Correct 1746 ms 235880 KB Output is correct
85 Correct 1376 ms 235748 KB Output is correct
86 Correct 1327 ms 191464 KB Output is correct
87 Correct 758 ms 100776 KB Output is correct
88 Correct 878 ms 132476 KB Output is correct
89 Correct 1276 ms 220208 KB Output is correct
90 Correct 1663 ms 231416 KB Output is correct
91 Correct 1860 ms 231336 KB Output is correct