답안 #683827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683827 2023-01-19T12:18:30 Z S2speed 무지개나라 (APIO17_rainbow) C++17
100 / 100
882 ms 193288 KB
#include "rainbow.h"
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define sze(x) (int)(x.size())
#define mp(x , y) make_pair(x , y)
#define wall cout<<"--------------------------------------\n";
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;
typedef double db;
typedef pair<pll , ll> plll;
typedef pair<int , pii> piii;
typedef pair<pll , pll> pllll;

const ll maxn = 2e5 + 17 , md = 1e9 + 7 , inf = 2e8;

vector<int> merge(vector<int> &a , vector<int> &b){
	vector<int> res;
	int as = sze(a) , bs = sze(b);
	a.push_back(inf); b.push_back(inf);
	int x = 0 , y = 0;
	for(int e = 0 ; e < as + bs ; e++){
		if(a[x] < b[y]){
			res.push_back(a[x++]);
		} else {
			res.push_back(b[y++]);
		}
	}
	a.pop_back(); b.pop_back();
	return res;
}

struct segtree {

	int sz = 1;
	vector<vector<int>> val;

	void init(int n){
		while(sz < n) sz <<= 1;
		val.resize(sz << 1);
		return;
	}

	void add(int i , int k , int x , int lx , int rx){
		if(rx - lx == 1){
			val[x].push_back(k);
			return;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		if(i < m){
			add(i , k , ln , lx , m);
		} else {
			add(i , k , rn , m , rx);
		}
		return;
	}

	void add(int i , int k){
		add(i , k , 0 , 0 , sz);
		return;
	}

	void build(int x , int lx , int rx){
		if(rx - lx == 1){
			sort(all(val[x]));
			val[x].resize(distance(val[x].begin() , unique(all(val[x]))));
			return;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		build(ln , lx , m); build(rn , m , rx);
		val[x] = merge(val[ln] , val[rn]);
		return;
	}

	void build(){
		build(0 , 0 , sz);
		return;
	}

	int cal(int l1 , int r1 , int l2 , int r2 , int x , int lx , int rx){
		if(rx <= l1 || lx >= r1) return 0;
		if(rx <= r1 && lx >= l1){
			int res = lower_bound(all(val[x]) , r2) - lower_bound(all(val[x]) , l2);
			return res;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		int a = cal(l1 , r1 , l2 , r2 , ln , lx , m) , b = cal(l1 , r1 , l2 , r2 , rn , m , rx);
		return a + b;
	}

	int cal(int l1 , int r1 , int l2 , int r2){
		return cal(l1 , r1 , l2 , r2 , 0 , 0 , sz);
	}

};

segtree v , e[2] , f;
vector<int> vx[maxn] , vy[maxn];

void add(int x , int y){
	v.add(x , y);
	e[0].add(x - 1 , y); e[0].add(x , y);
	e[1].add(x , y - 1); e[1].add(x , y);
	f.add(x - 1 , y - 1); f.add(x - 1 , y); f.add(x , y - 1); f.add(x , y);
	vx[x].push_back(y); vy[y].push_back(x);
	return;
}

void init(int n , int m , int sx , int sy , int k , char *s){
	v.init(n + 1); e[0].init(n + 1); e[1].init(n + 1); f.init(n + 1);
	int x = sx , y = sy;
	for(int i = 0 ; ; i++){
		add(x , y);
		if(i == k) break;
		if(s[i] == 'N'){
			x--;
		} else if(s[i] == 'S'){
			x++;
		} else if(s[i] == 'E'){
			y++;
		} else {
			y--;
		}
	}
	for(int i = 1 ; i <= n ; i++){
		sort(all(vx[i]));
	}
	for(int i = 1 ; i <= m ; i++){
		sort(all(vy[i]));
	}
	v.build(); e[0].build(); e[1].build(); f.build();
	return;
}

bool mohit(int x1 , int y1 , int x2 , int y2){
	int res = 0;
	res += lower_bound(all(vx[x1]) , y2) - lower_bound(all(vx[x1]) , y1);
	res += lower_bound(all(vx[x2 - 1]) , y2) - lower_bound(all(vx[x2 - 1]) , y1);
	res += lower_bound(all(vy[y1]) , x2) - lower_bound(all(vy[y1]) , x1);
	res += lower_bound(all(vy[y2 - 1]) , x2) - lower_bound(all(vy[y2 - 1]) , x1);
	return (res > 0);
}

int colour(int l1 , int l2 , int r1 , int r2){
	r1++; r2++;
	ll h = v.cal(l1 , r1 , l2 , r2);
	if(h == 0) return 1;
	ll V = 1ll * (r1 - l1) * (r2 - l2) - h;
	ll E = 1ll * (r1 - l1) * (r2 - l2 - 1) + 1ll * (r1 - l1 - 1) * (r2 - l2);
	E -= e[0].cal(l1 , r1 - 1 , l2 , r2) + e[1].cal(l1 , r1 , l2 , r2 - 1);
	ll F = 1ll * (r1 - l1 - 1) * (r2 - l2 - 1) - f.cal(l1 , r1 - 1 , l2 , r2 - 1) + 1 + !mohit(l1 , l2 , r1 , r2);
	return V - E + F - 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9772 KB Output is correct
2 Correct 10 ms 9940 KB Output is correct
3 Correct 8 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 9 ms 10068 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9708 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9708 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 8 ms 9968 KB Output is correct
13 Correct 9 ms 10068 KB Output is correct
14 Correct 10 ms 10264 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9704 KB Output is correct
17 Correct 5 ms 9660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9660 KB Output is correct
3 Correct 158 ms 19128 KB Output is correct
4 Correct 186 ms 23992 KB Output is correct
5 Correct 185 ms 23752 KB Output is correct
6 Correct 145 ms 21484 KB Output is correct
7 Correct 172 ms 21444 KB Output is correct
8 Correct 93 ms 15944 KB Output is correct
9 Correct 202 ms 24064 KB Output is correct
10 Correct 195 ms 23912 KB Output is correct
11 Correct 156 ms 21588 KB Output is correct
12 Correct 107 ms 23488 KB Output is correct
13 Correct 104 ms 24060 KB Output is correct
14 Correct 102 ms 23676 KB Output is correct
15 Correct 110 ms 21552 KB Output is correct
16 Correct 140 ms 20644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 306 ms 175268 KB Output is correct
3 Correct 380 ms 189740 KB Output is correct
4 Correct 363 ms 183980 KB Output is correct
5 Correct 325 ms 170632 KB Output is correct
6 Correct 281 ms 140452 KB Output is correct
7 Correct 281 ms 148356 KB Output is correct
8 Correct 57 ms 23776 KB Output is correct
9 Correct 61 ms 25244 KB Output is correct
10 Correct 140 ms 78416 KB Output is correct
11 Correct 199 ms 94332 KB Output is correct
12 Correct 308 ms 175244 KB Output is correct
13 Correct 381 ms 189832 KB Output is correct
14 Correct 349 ms 183872 KB Output is correct
15 Correct 330 ms 170676 KB Output is correct
16 Correct 266 ms 137860 KB Output is correct
17 Correct 285 ms 149212 KB Output is correct
18 Correct 352 ms 176364 KB Output is correct
19 Correct 392 ms 182500 KB Output is correct
20 Correct 390 ms 182636 KB Output is correct
21 Correct 60 ms 23780 KB Output is correct
22 Correct 68 ms 25356 KB Output is correct
23 Correct 139 ms 78392 KB Output is correct
24 Correct 190 ms 94320 KB Output is correct
25 Correct 306 ms 175196 KB Output is correct
26 Correct 378 ms 189756 KB Output is correct
27 Correct 362 ms 183816 KB Output is correct
28 Correct 329 ms 170524 KB Output is correct
29 Correct 278 ms 137844 KB Output is correct
30 Correct 285 ms 149152 KB Output is correct
31 Correct 326 ms 176452 KB Output is correct
32 Correct 336 ms 182376 KB Output is correct
33 Correct 334 ms 182476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9772 KB Output is correct
2 Correct 10 ms 9940 KB Output is correct
3 Correct 8 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 9 ms 10068 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9708 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9708 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 8 ms 9968 KB Output is correct
13 Correct 9 ms 10068 KB Output is correct
14 Correct 10 ms 10264 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9704 KB Output is correct
17 Correct 5 ms 9660 KB Output is correct
18 Correct 882 ms 34880 KB Output is correct
19 Correct 110 ms 13872 KB Output is correct
20 Correct 108 ms 13180 KB Output is correct
21 Correct 100 ms 13408 KB Output is correct
22 Correct 101 ms 13772 KB Output is correct
23 Correct 97 ms 13768 KB Output is correct
24 Correct 163 ms 13388 KB Output is correct
25 Correct 155 ms 13648 KB Output is correct
26 Correct 118 ms 14004 KB Output is correct
27 Correct 295 ms 32064 KB Output is correct
28 Correct 292 ms 25444 KB Output is correct
29 Correct 318 ms 30508 KB Output is correct
30 Correct 581 ms 48224 KB Output is correct
31 Correct 8 ms 9812 KB Output is correct
32 Correct 699 ms 32384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9772 KB Output is correct
2 Correct 10 ms 9940 KB Output is correct
3 Correct 8 ms 9812 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 9 ms 10068 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9708 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9708 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 7 ms 9812 KB Output is correct
12 Correct 8 ms 9968 KB Output is correct
13 Correct 9 ms 10068 KB Output is correct
14 Correct 10 ms 10264 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9704 KB Output is correct
17 Correct 5 ms 9660 KB Output is correct
18 Correct 882 ms 34880 KB Output is correct
19 Correct 110 ms 13872 KB Output is correct
20 Correct 108 ms 13180 KB Output is correct
21 Correct 100 ms 13408 KB Output is correct
22 Correct 101 ms 13772 KB Output is correct
23 Correct 97 ms 13768 KB Output is correct
24 Correct 163 ms 13388 KB Output is correct
25 Correct 155 ms 13648 KB Output is correct
26 Correct 118 ms 14004 KB Output is correct
27 Correct 295 ms 32064 KB Output is correct
28 Correct 292 ms 25444 KB Output is correct
29 Correct 318 ms 30508 KB Output is correct
30 Correct 581 ms 48224 KB Output is correct
31 Correct 8 ms 9812 KB Output is correct
32 Correct 699 ms 32384 KB Output is correct
33 Correct 306 ms 175268 KB Output is correct
34 Correct 380 ms 189740 KB Output is correct
35 Correct 363 ms 183980 KB Output is correct
36 Correct 325 ms 170632 KB Output is correct
37 Correct 281 ms 140452 KB Output is correct
38 Correct 281 ms 148356 KB Output is correct
39 Correct 57 ms 23776 KB Output is correct
40 Correct 61 ms 25244 KB Output is correct
41 Correct 140 ms 78416 KB Output is correct
42 Correct 199 ms 94332 KB Output is correct
43 Correct 308 ms 175244 KB Output is correct
44 Correct 381 ms 189832 KB Output is correct
45 Correct 349 ms 183872 KB Output is correct
46 Correct 330 ms 170676 KB Output is correct
47 Correct 266 ms 137860 KB Output is correct
48 Correct 285 ms 149212 KB Output is correct
49 Correct 352 ms 176364 KB Output is correct
50 Correct 392 ms 182500 KB Output is correct
51 Correct 390 ms 182636 KB Output is correct
52 Correct 60 ms 23780 KB Output is correct
53 Correct 68 ms 25356 KB Output is correct
54 Correct 139 ms 78392 KB Output is correct
55 Correct 190 ms 94320 KB Output is correct
56 Correct 306 ms 175196 KB Output is correct
57 Correct 378 ms 189756 KB Output is correct
58 Correct 362 ms 183816 KB Output is correct
59 Correct 329 ms 170524 KB Output is correct
60 Correct 278 ms 137844 KB Output is correct
61 Correct 285 ms 149152 KB Output is correct
62 Correct 326 ms 176452 KB Output is correct
63 Correct 336 ms 182376 KB Output is correct
64 Correct 334 ms 182476 KB Output is correct
65 Correct 158 ms 19128 KB Output is correct
66 Correct 186 ms 23992 KB Output is correct
67 Correct 185 ms 23752 KB Output is correct
68 Correct 145 ms 21484 KB Output is correct
69 Correct 172 ms 21444 KB Output is correct
70 Correct 93 ms 15944 KB Output is correct
71 Correct 202 ms 24064 KB Output is correct
72 Correct 195 ms 23912 KB Output is correct
73 Correct 156 ms 21588 KB Output is correct
74 Correct 107 ms 23488 KB Output is correct
75 Correct 104 ms 24060 KB Output is correct
76 Correct 102 ms 23676 KB Output is correct
77 Correct 110 ms 21552 KB Output is correct
78 Correct 140 ms 20644 KB Output is correct
79 Correct 322 ms 27108 KB Output is correct
80 Correct 373 ms 28760 KB Output is correct
81 Correct 401 ms 81656 KB Output is correct
82 Correct 505 ms 97436 KB Output is correct
83 Correct 511 ms 178132 KB Output is correct
84 Correct 718 ms 193288 KB Output is correct
85 Correct 517 ms 186748 KB Output is correct
86 Correct 538 ms 173456 KB Output is correct
87 Correct 411 ms 141436 KB Output is correct
88 Correct 406 ms 152768 KB Output is correct
89 Correct 403 ms 179288 KB Output is correct
90 Correct 649 ms 185384 KB Output is correct
91 Correct 845 ms 185480 KB Output is correct