Submission #738696

# Submission time Handle Problem Language Result Execution time Memory
738696 2023-05-09T12:03:55 Z myrcella Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
960 ms 147220 KB
//by szh
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
 
#include "rainbow.h"
 
const int maxn = 1e6+10;
 
int r,c;
vector <pii> river;

struct psegtree{
	int rt[maxn<<4],tree[maxn<<4],ls[maxn<<4],rs[maxn<<4];
	vector <pii> pos;
	int tot;
	
	int update(int k,int l,int r,int root) {
		int cur = tot++;
		if (root==-1) tree[cur]=1;
		else tree[cur] = tree[root] + 1;
		ls[cur] = root==-1?-1:ls[root],rs[cur] = root==-1?-1:rs[root];
		if (l==r) return cur;
		int mid=l+r>>1;
		if (k<=mid) ls[cur] = update(k,l,mid,ls[cur]);
		else rs[cur] = update(k,mid+1,r,rs[cur]);
		return cur;
	}
	void init() {
		sort(ALL(pos));
		pos.erase(unique(ALL(pos)),pos.end());
		tot = 0;
		rt[0] = tot++,tree[0]=0,ls[0] = rs[0] = -1;
		rep(i,0,SZ(pos)) {
			rt[i+1] = update(pos[i].se,0,c,rt[i]);
			assert(tree[rt[i+1]]==i+1);
		}
	}
	int query(int node,int cl,int cr,int l,int r) {
		if (node==-1) return 0;
		if (l<=cl and cr<=r) return tree[node];
		int mid = cl+cr>>1;
		int ret = 0;
		if (l<=mid) ret += query(ls[node],cl,mid,l,r);
		if (r>mid) ret += query(rs[node],mid+1,cr,l,r);
		return ret;
	}
	int query(int ar,int ac,int br,int bc) {
		int ed = upper_bound(ALL(pos),MP(br,mod))-pos.begin();
		int bg = lower_bound(ALL(pos),MP(ar,-1))-pos.begin();
		return query(rt[ed],0,c,ac,bc) - query(rt[bg],0,c,ac,bc);
	}
}node,horizontal,vertical,grid;
int minr = mod,maxr=-1,minc = mod,maxc = -1;

void init(int R, int C, int sr, int sc, int M, char *S) {
	r = R, c = C;
	river.pb({sr,sc});
	minr = min(minr,sr),maxr = max(maxr,sr);
	minc = min(minc,sc),maxc = max(maxc,sc);
	rep(i,0,M) {
		if (S[i]=='S') sr++;
		else if (S[i]=='E') sc++;
		else if (S[i]=='W') sc--;
		else sr--;
		river.pb({sr,sc});
		minr = min(minr,sr),maxr = max(maxr,sr);
		minc = min(minc,sc),maxc = max(maxc,sc);
	}
	node.rt[0] = 0;
	horizontal.rt[0] = 0;
	vertical.rt[0] = 0;
	grid.rt[0] = 0;
	rep(i,0,SZ(river)) {
		node.pos.pb(river[i]);
		horizontal.pos.pb({river[i].fi,river[i].se-1});
		horizontal.pos.pb(river[i]);
		vertical.pos.pb({river[i].fi-1,river[i].se});
		vertical.pos.pb(river[i]);
		grid.pos.pb({river[i].fi-1,river[i].se});
		grid.pos.pb({river[i].fi,river[i].se-1});
		grid.pos.pb({river[i].fi-1,river[i].se-1});
		grid.pos.pb({river[i].fi,river[i].se});
	}
	node.init();
	horizontal.init();
	vertical.init();
	grid.init();
}
 
int colour(int ar, int ac, int br, int bc) {
	ll V = 1ll*(br-ar+1)*(bc-ac+1) - node.query(ar,ac,br,bc);
	ll E = 1ll*(br-ar+1)*(bc-ac) - horizontal.query(ar,ac,br,bc-1) 
	     + 1ll*(br-ar)*(bc-ac+1) - vertical.query(ar,ac,br-1,bc);
	ll F = 1ll*(br-ar)*(bc-ac) - grid.query(ar,ac,br-1,bc-1);
	
//	debug(V),debug(E),debug(F);
	
	if (ar<minr and ac<minc and br>maxr and bc>maxc) F++;
	return V-E+F;
}

Compilation message

rainbow.cpp: In member function 'int psegtree::update(int, int, int, int)':
rainbow.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |   int mid=l+r>>1;
      |           ~^~
rainbow.cpp: In member function 'int psegtree::query(int, int, int, int, int)':
rainbow.cpp:60:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |   int mid = cl+cr>>1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 4 ms 1364 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 4 ms 1248 KB Output is correct
14 Correct 6 ms 1752 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 360 ms 87420 KB Output is correct
4 Correct 552 ms 146228 KB Output is correct
5 Correct 543 ms 145112 KB Output is correct
6 Correct 382 ms 114352 KB Output is correct
7 Correct 523 ms 112648 KB Output is correct
8 Correct 112 ms 12080 KB Output is correct
9 Correct 556 ms 146132 KB Output is correct
10 Correct 550 ms 145004 KB Output is correct
11 Correct 444 ms 114384 KB Output is correct
12 Correct 244 ms 136032 KB Output is correct
13 Correct 279 ms 146096 KB Output is correct
14 Correct 303 ms 144984 KB Output is correct
15 Correct 300 ms 114572 KB Output is correct
16 Correct 393 ms 104408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 152 ms 144668 KB Output is correct
3 Correct 117 ms 142048 KB Output is correct
4 Correct 119 ms 144564 KB Output is correct
5 Correct 110 ms 108872 KB Output is correct
6 Correct 86 ms 35660 KB Output is correct
7 Correct 108 ms 60612 KB Output is correct
8 Correct 150 ms 115524 KB Output is correct
9 Correct 151 ms 101272 KB Output is correct
10 Correct 51 ms 22020 KB Output is correct
11 Correct 105 ms 66452 KB Output is correct
12 Correct 153 ms 144652 KB Output is correct
13 Correct 122 ms 142152 KB Output is correct
14 Correct 127 ms 144636 KB Output is correct
15 Correct 107 ms 108868 KB Output is correct
16 Correct 88 ms 30588 KB Output is correct
17 Correct 107 ms 60616 KB Output is correct
18 Correct 158 ms 144672 KB Output is correct
19 Correct 147 ms 145828 KB Output is correct
20 Correct 145 ms 145612 KB Output is correct
21 Correct 158 ms 115568 KB Output is correct
22 Correct 149 ms 101168 KB Output is correct
23 Correct 53 ms 22084 KB Output is correct
24 Correct 112 ms 66532 KB Output is correct
25 Correct 156 ms 144608 KB Output is correct
26 Correct 110 ms 142132 KB Output is correct
27 Correct 125 ms 144632 KB Output is correct
28 Correct 108 ms 108832 KB Output is correct
29 Correct 92 ms 30664 KB Output is correct
30 Correct 108 ms 60648 KB Output is correct
31 Correct 151 ms 144600 KB Output is correct
32 Correct 129 ms 145712 KB Output is correct
33 Correct 133 ms 145588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 4 ms 1364 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 4 ms 1248 KB Output is correct
14 Correct 6 ms 1752 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 781 ms 52320 KB Output is correct
19 Correct 218 ms 4176 KB Output is correct
20 Correct 160 ms 2184 KB Output is correct
21 Correct 179 ms 2532 KB Output is correct
22 Correct 216 ms 3020 KB Output is correct
23 Correct 220 ms 4044 KB Output is correct
24 Correct 171 ms 2760 KB Output is correct
25 Correct 192 ms 3100 KB Output is correct
26 Correct 204 ms 3384 KB Output is correct
27 Correct 319 ms 44600 KB Output is correct
28 Correct 233 ms 27692 KB Output is correct
29 Correct 288 ms 41772 KB Output is correct
30 Correct 465 ms 91852 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 567 ms 44860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 4 ms 1364 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 4 ms 1248 KB Output is correct
14 Correct 6 ms 1752 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 781 ms 52320 KB Output is correct
19 Correct 218 ms 4176 KB Output is correct
20 Correct 160 ms 2184 KB Output is correct
21 Correct 179 ms 2532 KB Output is correct
22 Correct 216 ms 3020 KB Output is correct
23 Correct 220 ms 4044 KB Output is correct
24 Correct 171 ms 2760 KB Output is correct
25 Correct 192 ms 3100 KB Output is correct
26 Correct 204 ms 3384 KB Output is correct
27 Correct 319 ms 44600 KB Output is correct
28 Correct 233 ms 27692 KB Output is correct
29 Correct 288 ms 41772 KB Output is correct
30 Correct 465 ms 91852 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 567 ms 44860 KB Output is correct
33 Correct 152 ms 144668 KB Output is correct
34 Correct 117 ms 142048 KB Output is correct
35 Correct 119 ms 144564 KB Output is correct
36 Correct 110 ms 108872 KB Output is correct
37 Correct 86 ms 35660 KB Output is correct
38 Correct 108 ms 60612 KB Output is correct
39 Correct 150 ms 115524 KB Output is correct
40 Correct 151 ms 101272 KB Output is correct
41 Correct 51 ms 22020 KB Output is correct
42 Correct 105 ms 66452 KB Output is correct
43 Correct 153 ms 144652 KB Output is correct
44 Correct 122 ms 142152 KB Output is correct
45 Correct 127 ms 144636 KB Output is correct
46 Correct 107 ms 108868 KB Output is correct
47 Correct 88 ms 30588 KB Output is correct
48 Correct 107 ms 60616 KB Output is correct
49 Correct 158 ms 144672 KB Output is correct
50 Correct 147 ms 145828 KB Output is correct
51 Correct 145 ms 145612 KB Output is correct
52 Correct 158 ms 115568 KB Output is correct
53 Correct 149 ms 101168 KB Output is correct
54 Correct 53 ms 22084 KB Output is correct
55 Correct 112 ms 66532 KB Output is correct
56 Correct 156 ms 144608 KB Output is correct
57 Correct 110 ms 142132 KB Output is correct
58 Correct 125 ms 144632 KB Output is correct
59 Correct 108 ms 108832 KB Output is correct
60 Correct 92 ms 30664 KB Output is correct
61 Correct 108 ms 60648 KB Output is correct
62 Correct 151 ms 144600 KB Output is correct
63 Correct 129 ms 145712 KB Output is correct
64 Correct 133 ms 145588 KB Output is correct
65 Correct 360 ms 87420 KB Output is correct
66 Correct 552 ms 146228 KB Output is correct
67 Correct 543 ms 145112 KB Output is correct
68 Correct 382 ms 114352 KB Output is correct
69 Correct 523 ms 112648 KB Output is correct
70 Correct 112 ms 12080 KB Output is correct
71 Correct 556 ms 146132 KB Output is correct
72 Correct 550 ms 145004 KB Output is correct
73 Correct 444 ms 114384 KB Output is correct
74 Correct 244 ms 136032 KB Output is correct
75 Correct 279 ms 146096 KB Output is correct
76 Correct 303 ms 144984 KB Output is correct
77 Correct 300 ms 114572 KB Output is correct
78 Correct 393 ms 104408 KB Output is correct
79 Correct 951 ms 117000 KB Output is correct
80 Correct 960 ms 102828 KB Output is correct
81 Correct 346 ms 23632 KB Output is correct
82 Correct 376 ms 68076 KB Output is correct
83 Correct 414 ms 146148 KB Output is correct
84 Correct 302 ms 143624 KB Output is correct
85 Correct 333 ms 146096 KB Output is correct
86 Correct 279 ms 110356 KB Output is correct
87 Correct 159 ms 32096 KB Output is correct
88 Correct 184 ms 62112 KB Output is correct
89 Correct 236 ms 146256 KB Output is correct
90 Correct 458 ms 147220 KB Output is correct
91 Correct 423 ms 147084 KB Output is correct