Submission #471431

# Submission time Handle Problem Language Result Execution time Memory
471431 2021-09-09T07:11:37 Z CSQ31 Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
1216 ms 124788 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int r,c;
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define pb push_back
typedef pair<int,int> pii;
const int MAXN = 2e5;
struct fen{
	vector<vector<int>>bit;
	vector<set<int>>data;
	int r,c;
	fen(){}
	fen(int _r,int _c){
		r = _r;
		c = _c;
		bit.resize(r+1);
		data.resize(r+1);
	}
	
	void add(int x,int y){
		data[x].insert(y);
	}
	int query(int x,int l,int r){
		int res = 0;
		for(int i=x;i;i-=i&(-i)){
			int p = lower_bound(all(bit[i]),l) - bit[i].begin();
			int q = upper_bound(all(bit[i]),r) - bit[i].begin();
			res+=q-p;
		}
		return res;
	}
	int query(int xl,int xr,int yl,int yr){
		if(xl > xr)return 0;
		return query(xr,yl,yr) - query(xl-1,yl,yr);
	}
	
	void build(){
		for(int i=1;i<=r;i++){
			for(int j=i;j<=r;j+=j&(-j)){
				for(int x:data[i])bit[j].pb(x);
			}
		}
		for(int i=1;i<=r;i++)sort(all(bit[i]));
	}
}river,hedge,vedge,vert;
pii mx = {-1e9,-1e9};
pii mn = {1e9,1e9};
void init(int R, int C, int sr, int sc, int M, char *S) {
	r = R;
	c = C;
	river = fen(r,c);
	hedge = fen(r+1,c);
	vedge = fen(r,c+1);
	vert = fen(r+1,c+1);
    int x = sr;
	int y = sc;
	for(int i=-1;i<M;i++){
		if(i>=0){
			char c = S[i];
			if(c =='N')x--;
			if(c =='S')x++;
			if(c =='W')y--;
			if(c =='E')y++;
		}
		river.add(x,y);
		hedge.add(x,y);
		hedge.add(x+1,y);
		vedge.add(x,y);
		vedge.add(x,y+1);
		vert.add(x,y);
		vert.add(x+1,y);
		vert.add(x,y+1);
		vert.add(x+1,y+1);
		mx.fi = max(mx.fi,x);
		mx.se = max(mx.se,y);
		mn.fi = min(mn.fi,x);
		mn.se = min(mn.se,y);
	}
	river.build();
	vert.build();
	hedge.build();
	vedge.build();
}

int colour(int ar, int ac, int br, int bc) {
	int C = (!(mn.fi <= ar || mn.se <= ac || mx.fi >= br || mx.se >= bc)) + 1;
	int A = river.query(ar,br,ac,bc);
	int V = vert.query(ar+1,br,ac+1,bc);
	int E = hedge.query(ar+1,br,ac,bc) + vedge.query(ar,br,ac+1,bc);
	//cout<<E<<" "<<V<<" "<<A<<" "<<C<<'\n';
	int F = 1+C+E-V;
    return F - A - 1;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 4 ms 332 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 7 ms 936 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 277 ms 20028 KB Output is correct
4 Correct 419 ms 33024 KB Output is correct
5 Correct 436 ms 32828 KB Output is correct
6 Correct 415 ms 25788 KB Output is correct
7 Correct 405 ms 25276 KB Output is correct
8 Correct 68 ms 1156 KB Output is correct
9 Correct 418 ms 33004 KB Output is correct
10 Correct 438 ms 32824 KB Output is correct
11 Correct 414 ms 25712 KB Output is correct
12 Correct 338 ms 30608 KB Output is correct
13 Correct 330 ms 32996 KB Output is correct
14 Correct 366 ms 32824 KB Output is correct
15 Correct 361 ms 25796 KB Output is correct
16 Correct 319 ms 23956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 907 ms 108304 KB Output is correct
3 Correct 273 ms 115252 KB Output is correct
4 Correct 315 ms 115572 KB Output is correct
5 Correct 328 ms 99428 KB Output is correct
6 Correct 163 ms 67292 KB Output is correct
7 Correct 242 ms 75324 KB Output is correct
8 Correct 261 ms 29652 KB Output is correct
9 Correct 262 ms 27728 KB Output is correct
10 Correct 105 ms 35948 KB Output is correct
11 Correct 177 ms 46528 KB Output is correct
12 Correct 907 ms 108408 KB Output is correct
13 Correct 271 ms 115256 KB Output is correct
14 Correct 316 ms 115672 KB Output is correct
15 Correct 325 ms 99416 KB Output is correct
16 Correct 153 ms 65216 KB Output is correct
17 Correct 258 ms 79016 KB Output is correct
18 Correct 611 ms 124264 KB Output is correct
19 Correct 561 ms 114516 KB Output is correct
20 Correct 663 ms 118188 KB Output is correct
21 Correct 272 ms 29752 KB Output is correct
22 Correct 269 ms 27728 KB Output is correct
23 Correct 108 ms 35736 KB Output is correct
24 Correct 183 ms 46568 KB Output is correct
25 Correct 920 ms 108376 KB Output is correct
26 Correct 274 ms 115364 KB Output is correct
27 Correct 309 ms 115492 KB Output is correct
28 Correct 335 ms 99452 KB Output is correct
29 Correct 154 ms 65200 KB Output is correct
30 Correct 266 ms 79032 KB Output is correct
31 Correct 611 ms 124264 KB Output is correct
32 Correct 556 ms 114680 KB Output is correct
33 Correct 632 ms 117944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 4 ms 332 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 7 ms 936 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 938 ms 23336 KB Output is correct
19 Correct 255 ms 1860 KB Output is correct
20 Correct 191 ms 1124 KB Output is correct
21 Correct 218 ms 1384 KB Output is correct
22 Correct 246 ms 1532 KB Output is correct
23 Correct 232 ms 1916 KB Output is correct
24 Correct 237 ms 1248 KB Output is correct
25 Correct 244 ms 1544 KB Output is correct
26 Correct 261 ms 1744 KB Output is correct
27 Correct 381 ms 17876 KB Output is correct
28 Correct 320 ms 9756 KB Output is correct
29 Correct 362 ms 16324 KB Output is correct
30 Correct 867 ms 45880 KB Output is correct
31 Correct 5 ms 332 KB Output is correct
32 Correct 609 ms 19188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 4 ms 332 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 7 ms 936 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 938 ms 23336 KB Output is correct
19 Correct 255 ms 1860 KB Output is correct
20 Correct 191 ms 1124 KB Output is correct
21 Correct 218 ms 1384 KB Output is correct
22 Correct 246 ms 1532 KB Output is correct
23 Correct 232 ms 1916 KB Output is correct
24 Correct 237 ms 1248 KB Output is correct
25 Correct 244 ms 1544 KB Output is correct
26 Correct 261 ms 1744 KB Output is correct
27 Correct 381 ms 17876 KB Output is correct
28 Correct 320 ms 9756 KB Output is correct
29 Correct 362 ms 16324 KB Output is correct
30 Correct 867 ms 45880 KB Output is correct
31 Correct 5 ms 332 KB Output is correct
32 Correct 609 ms 19188 KB Output is correct
33 Correct 907 ms 108304 KB Output is correct
34 Correct 273 ms 115252 KB Output is correct
35 Correct 315 ms 115572 KB Output is correct
36 Correct 328 ms 99428 KB Output is correct
37 Correct 163 ms 67292 KB Output is correct
38 Correct 242 ms 75324 KB Output is correct
39 Correct 261 ms 29652 KB Output is correct
40 Correct 262 ms 27728 KB Output is correct
41 Correct 105 ms 35948 KB Output is correct
42 Correct 177 ms 46528 KB Output is correct
43 Correct 907 ms 108408 KB Output is correct
44 Correct 271 ms 115256 KB Output is correct
45 Correct 316 ms 115672 KB Output is correct
46 Correct 325 ms 99416 KB Output is correct
47 Correct 153 ms 65216 KB Output is correct
48 Correct 258 ms 79016 KB Output is correct
49 Correct 611 ms 124264 KB Output is correct
50 Correct 561 ms 114516 KB Output is correct
51 Correct 663 ms 118188 KB Output is correct
52 Correct 272 ms 29752 KB Output is correct
53 Correct 269 ms 27728 KB Output is correct
54 Correct 108 ms 35736 KB Output is correct
55 Correct 183 ms 46568 KB Output is correct
56 Correct 920 ms 108376 KB Output is correct
57 Correct 274 ms 115364 KB Output is correct
58 Correct 309 ms 115492 KB Output is correct
59 Correct 335 ms 99452 KB Output is correct
60 Correct 154 ms 65200 KB Output is correct
61 Correct 266 ms 79032 KB Output is correct
62 Correct 611 ms 124264 KB Output is correct
63 Correct 556 ms 114680 KB Output is correct
64 Correct 632 ms 117944 KB Output is correct
65 Correct 277 ms 20028 KB Output is correct
66 Correct 419 ms 33024 KB Output is correct
67 Correct 436 ms 32828 KB Output is correct
68 Correct 415 ms 25788 KB Output is correct
69 Correct 405 ms 25276 KB Output is correct
70 Correct 68 ms 1156 KB Output is correct
71 Correct 418 ms 33004 KB Output is correct
72 Correct 438 ms 32824 KB Output is correct
73 Correct 414 ms 25712 KB Output is correct
74 Correct 338 ms 30608 KB Output is correct
75 Correct 330 ms 32996 KB Output is correct
76 Correct 366 ms 32824 KB Output is correct
77 Correct 361 ms 25796 KB Output is correct
78 Correct 319 ms 23956 KB Output is correct
79 Correct 613 ms 30612 KB Output is correct
80 Correct 636 ms 28472 KB Output is correct
81 Correct 354 ms 36504 KB Output is correct
82 Correct 462 ms 47300 KB Output is correct
83 Correct 1216 ms 109200 KB Output is correct
84 Correct 810 ms 115888 KB Output is correct
85 Correct 702 ms 116304 KB Output is correct
86 Correct 707 ms 100088 KB Output is correct
87 Correct 323 ms 65860 KB Output is correct
88 Correct 471 ms 79712 KB Output is correct
89 Correct 803 ms 124788 KB Output is correct
90 Correct 1060 ms 115188 KB Output is correct
91 Correct 925 ms 118744 KB Output is correct