답안 #819702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819702 2023-08-10T12:43:15 Z Meloric 무지개나라 (APIO17_rainbow) C++14
100 / 100
610 ms 204628 KB
#include <bits/stdc++.h>
#define pb push_back
//#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

using namespace std;

//const int inf = 1e18;

void p(auto A){
	for(auto e : A)cout << e << ' ';
	cout << '\n';
}

// A = 1 - V + E - F'
//   = 1 - 2 + 6 - 3
//   = 1 - 4 + 12 - 6 
//   = 1 - 2 + 3 - 1 = 1
const int MAXQ = 100000;
const int MAXW = 200000;
//const int MAXW = 5;
//const int MAXQ = 2;

struct seg{
	array<set<int>, MAXW+5>events;
	array<int, MAXW+5> root;
	array<int, MAXQ*65> LC, RC, VAL;
	int node = 0;
	void upd(int prv, int& u, int tl, int tr, int pos, int val){
		if(tl > pos || tr < pos)return u=prv, void();
		u=++node;
		if(tl==tr)return VAL[u]=VAL[prv]+val, void();
		int tm=(tl+tr)/2;
		upd(LC[prv], LC[u], tl, tm, pos, val);
		upd(RC[prv], RC[u], tm+1, tr, pos, val);
		VAL[u] = VAL[LC[u]]+VAL[RC[u]];
	}
	int qer(int u, int tl, int tr, int l, int r){
		if(!u)return 0;
		if(tl > r || tr < l)return 0;
		if(tl >= l && tr <= r)return VAL[u];
		int tm = (tl+tr)/2;
		int ret = qer(LC[u], tl, tm, l, r)+qer(RC[u], tm+1, tr, l, r);
		return ret;
	}
	void init(){
		for(int i = 0; i< events.size(); i++){
			if(i)root[i]=root[i-1];
			for(auto e : events[i])upd(root[i], root[i], 0, MAXW+3, e, 1);
		}
	}
	int oqer(int x1, int x2, int y1, int y2){
		return -qer(root[x1-1], 0, MAXW+3, y1, y2)+qer(root[x2], 0, MAXW+3, y1, y2);
	}

}EH, EV, F, V;
int mnx=MAXW+5, mxx=0, mny=MAXW+5, mxy=0;

void add_river(int x, int y){
	mnx = min(mnx, x);
	mny = min(mny, y);
	mxx = max(mxx, x);
	mxy = max(mxy, y);
	F.events[x].insert(y);
	V.events[x].insert(y);
	V.events[x+1].insert(y);
	V.events[x].insert(y+1);
	V.events[x+1].insert(y+1);
	EH.events[x].insert(y);
	EH.events[x].insert(y+1);
	EV.events[x].insert(y);
	EV.events[x+1].insert(y);
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	add_river(sc, sr);
	for(int i = 0; i< M; i++){
		if(S[i]=='N')sr--;
		if(S[i]=='E')sc++;
		if(S[i]=='S')sr++;
		if(S[i]=='W')sc--;
		add_river(sc, sr);
	}
	EH.init();
	EV.init();
	F.init();
	V.init();
}

	
int colour(int ar, int ac, int br, int bc) {
	int ret = 1;
	if(ar < mny && ac < mnx && br > mxy && bc > mxx)ret++;
	ret-=V.oqer(ac+1, bc, ar+1, br);
	ret+=EV.oqer(ac+1, bc, ar, br);
	ret+=EH.oqer(ac, bc, ar+1, br);
	ret-=F.oqer(ac, bc, ar, br);
	return ret;
}
/*
void solve(){
	int r, c, m, q; cin >> r >> c >> m >> q;
	int sr, sc; cin >> sr >> sc;
	string S; cin >> S;
	init(r, c, sr, sc, m, &S[0]);
	
	for(int i = 0; i< q; i++){
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << colour(x1, y1, x2, y2) << '\n';
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t = 1;
	//cin >> t;
	while(t--)solve();
}
*/

Compilation message

rainbow.cpp:15:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   15 | void p(auto A){
      |        ^~~~
rainbow.cpp: In member function 'void seg::init()':
rainbow.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::array<std::set<int>, 200005>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int i = 0; i< events.size(); i++){
      |                  ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 41300 KB Output is correct
2 Correct 25 ms 42304 KB Output is correct
3 Correct 24 ms 41292 KB Output is correct
4 Correct 24 ms 41464 KB Output is correct
5 Correct 25 ms 42556 KB Output is correct
6 Correct 21 ms 41124 KB Output is correct
7 Correct 21 ms 41108 KB Output is correct
8 Correct 22 ms 41084 KB Output is correct
9 Correct 22 ms 41044 KB Output is correct
10 Correct 21 ms 41048 KB Output is correct
11 Correct 23 ms 41632 KB Output is correct
12 Correct 27 ms 42196 KB Output is correct
13 Correct 27 ms 43164 KB Output is correct
14 Correct 27 ms 43576 KB Output is correct
15 Correct 22 ms 41044 KB Output is correct
16 Correct 22 ms 41044 KB Output is correct
17 Correct 22 ms 41064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 41044 KB Output is correct
2 Correct 22 ms 41064 KB Output is correct
3 Correct 303 ms 138396 KB Output is correct
4 Correct 411 ms 203860 KB Output is correct
5 Correct 409 ms 202428 KB Output is correct
6 Correct 329 ms 165444 KB Output is correct
7 Correct 381 ms 163288 KB Output is correct
8 Correct 95 ms 41828 KB Output is correct
9 Correct 411 ms 203808 KB Output is correct
10 Correct 440 ms 202392 KB Output is correct
11 Correct 341 ms 165404 KB Output is correct
12 Correct 228 ms 192524 KB Output is correct
13 Correct 227 ms 203700 KB Output is correct
14 Correct 233 ms 202412 KB Output is correct
15 Correct 237 ms 165688 KB Output is correct
16 Correct 323 ms 156272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 41044 KB Output is correct
2 Correct 173 ms 200816 KB Output is correct
3 Correct 330 ms 201012 KB Output is correct
4 Correct 184 ms 201020 KB Output is correct
5 Correct 226 ms 160372 KB Output is correct
6 Correct 89 ms 71012 KB Output is correct
7 Correct 132 ms 100772 KB Output is correct
8 Correct 169 ms 183964 KB Output is correct
9 Correct 159 ms 169108 KB Output is correct
10 Correct 65 ms 72652 KB Output is correct
11 Correct 114 ms 119576 KB Output is correct
12 Correct 167 ms 200944 KB Output is correct
13 Correct 326 ms 201164 KB Output is correct
14 Correct 186 ms 201128 KB Output is correct
15 Correct 208 ms 160512 KB Output is correct
16 Correct 75 ms 65116 KB Output is correct
17 Correct 149 ms 101112 KB Output is correct
18 Correct 251 ms 201108 KB Output is correct
19 Correct 240 ms 199808 KB Output is correct
20 Correct 241 ms 199772 KB Output is correct
21 Correct 171 ms 183916 KB Output is correct
22 Correct 163 ms 169212 KB Output is correct
23 Correct 70 ms 72728 KB Output is correct
24 Correct 122 ms 119592 KB Output is correct
25 Correct 167 ms 200964 KB Output is correct
26 Correct 320 ms 201036 KB Output is correct
27 Correct 186 ms 201072 KB Output is correct
28 Correct 208 ms 160416 KB Output is correct
29 Correct 75 ms 65028 KB Output is correct
30 Correct 148 ms 100924 KB Output is correct
31 Correct 252 ms 201084 KB Output is correct
32 Correct 242 ms 199792 KB Output is correct
33 Correct 246 ms 199756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 41300 KB Output is correct
2 Correct 25 ms 42304 KB Output is correct
3 Correct 24 ms 41292 KB Output is correct
4 Correct 24 ms 41464 KB Output is correct
5 Correct 25 ms 42556 KB Output is correct
6 Correct 21 ms 41124 KB Output is correct
7 Correct 21 ms 41108 KB Output is correct
8 Correct 22 ms 41084 KB Output is correct
9 Correct 22 ms 41044 KB Output is correct
10 Correct 21 ms 41048 KB Output is correct
11 Correct 23 ms 41632 KB Output is correct
12 Correct 27 ms 42196 KB Output is correct
13 Correct 27 ms 43164 KB Output is correct
14 Correct 27 ms 43576 KB Output is correct
15 Correct 22 ms 41044 KB Output is correct
16 Correct 22 ms 41044 KB Output is correct
17 Correct 22 ms 41064 KB Output is correct
18 Correct 610 ms 125532 KB Output is correct
19 Correct 166 ms 48360 KB Output is correct
20 Correct 155 ms 45148 KB Output is correct
21 Correct 167 ms 45772 KB Output is correct
22 Correct 195 ms 46640 KB Output is correct
23 Correct 167 ms 47976 KB Output is correct
24 Correct 177 ms 45528 KB Output is correct
25 Correct 185 ms 46448 KB Output is correct
26 Correct 182 ms 46792 KB Output is correct
27 Correct 294 ms 109896 KB Output is correct
28 Correct 225 ms 76120 KB Output is correct
29 Correct 292 ms 104228 KB Output is correct
30 Correct 510 ms 204628 KB Output is correct
31 Correct 26 ms 41264 KB Output is correct
32 Correct 504 ms 110616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 41300 KB Output is correct
2 Correct 25 ms 42304 KB Output is correct
3 Correct 24 ms 41292 KB Output is correct
4 Correct 24 ms 41464 KB Output is correct
5 Correct 25 ms 42556 KB Output is correct
6 Correct 21 ms 41124 KB Output is correct
7 Correct 21 ms 41108 KB Output is correct
8 Correct 22 ms 41084 KB Output is correct
9 Correct 22 ms 41044 KB Output is correct
10 Correct 21 ms 41048 KB Output is correct
11 Correct 23 ms 41632 KB Output is correct
12 Correct 27 ms 42196 KB Output is correct
13 Correct 27 ms 43164 KB Output is correct
14 Correct 27 ms 43576 KB Output is correct
15 Correct 22 ms 41044 KB Output is correct
16 Correct 22 ms 41044 KB Output is correct
17 Correct 22 ms 41064 KB Output is correct
18 Correct 610 ms 125532 KB Output is correct
19 Correct 166 ms 48360 KB Output is correct
20 Correct 155 ms 45148 KB Output is correct
21 Correct 167 ms 45772 KB Output is correct
22 Correct 195 ms 46640 KB Output is correct
23 Correct 167 ms 47976 KB Output is correct
24 Correct 177 ms 45528 KB Output is correct
25 Correct 185 ms 46448 KB Output is correct
26 Correct 182 ms 46792 KB Output is correct
27 Correct 294 ms 109896 KB Output is correct
28 Correct 225 ms 76120 KB Output is correct
29 Correct 292 ms 104228 KB Output is correct
30 Correct 510 ms 204628 KB Output is correct
31 Correct 26 ms 41264 KB Output is correct
32 Correct 504 ms 110616 KB Output is correct
33 Correct 173 ms 200816 KB Output is correct
34 Correct 330 ms 201012 KB Output is correct
35 Correct 184 ms 201020 KB Output is correct
36 Correct 226 ms 160372 KB Output is correct
37 Correct 89 ms 71012 KB Output is correct
38 Correct 132 ms 100772 KB Output is correct
39 Correct 169 ms 183964 KB Output is correct
40 Correct 159 ms 169108 KB Output is correct
41 Correct 65 ms 72652 KB Output is correct
42 Correct 114 ms 119576 KB Output is correct
43 Correct 167 ms 200944 KB Output is correct
44 Correct 326 ms 201164 KB Output is correct
45 Correct 186 ms 201128 KB Output is correct
46 Correct 208 ms 160512 KB Output is correct
47 Correct 75 ms 65116 KB Output is correct
48 Correct 149 ms 101112 KB Output is correct
49 Correct 251 ms 201108 KB Output is correct
50 Correct 240 ms 199808 KB Output is correct
51 Correct 241 ms 199772 KB Output is correct
52 Correct 171 ms 183916 KB Output is correct
53 Correct 163 ms 169212 KB Output is correct
54 Correct 70 ms 72728 KB Output is correct
55 Correct 122 ms 119592 KB Output is correct
56 Correct 167 ms 200964 KB Output is correct
57 Correct 320 ms 201036 KB Output is correct
58 Correct 186 ms 201072 KB Output is correct
59 Correct 208 ms 160416 KB Output is correct
60 Correct 75 ms 65028 KB Output is correct
61 Correct 148 ms 100924 KB Output is correct
62 Correct 252 ms 201084 KB Output is correct
63 Correct 242 ms 199792 KB Output is correct
64 Correct 246 ms 199756 KB Output is correct
65 Correct 303 ms 138396 KB Output is correct
66 Correct 411 ms 203860 KB Output is correct
67 Correct 409 ms 202428 KB Output is correct
68 Correct 329 ms 165444 KB Output is correct
69 Correct 381 ms 163288 KB Output is correct
70 Correct 95 ms 41828 KB Output is correct
71 Correct 411 ms 203808 KB Output is correct
72 Correct 440 ms 202392 KB Output is correct
73 Correct 341 ms 165404 KB Output is correct
74 Correct 228 ms 192524 KB Output is correct
75 Correct 227 ms 203700 KB Output is correct
76 Correct 233 ms 202412 KB Output is correct
77 Correct 237 ms 165688 KB Output is correct
78 Correct 323 ms 156272 KB Output is correct
79 Correct 561 ms 187400 KB Output is correct
80 Correct 601 ms 172584 KB Output is correct
81 Correct 265 ms 76204 KB Output is correct
82 Correct 367 ms 122944 KB Output is correct
83 Correct 259 ms 204484 KB Output is correct
84 Correct 570 ms 204552 KB Output is correct
85 Correct 346 ms 204608 KB Output is correct
86 Correct 399 ms 164032 KB Output is correct
87 Correct 137 ms 68620 KB Output is correct
88 Correct 197 ms 104416 KB Output is correct
89 Correct 323 ms 204624 KB Output is correct
90 Correct 504 ms 203296 KB Output is correct
91 Correct 496 ms 203180 KB Output is correct