#include "werewolf.h"
#define pb push_back
#define VI vector<int>
#include<bits/stdc++.h>
using namespace std;
#define MXN 400100
struct node{
int l,r,val,lc,rc;
node():l(0){}
node(int l, int r, int val, int lc, int rc):l(l),r(r),val(val),lc(lc),rc(rc){}
node(int pos):l(pos),r(pos),val(1){}
} t[15*MXN];
int cnt;
int query(int i, int l, int r) {
if(!t[i].val||t[i].l>r||t[i].r<l)return 0;
if(l<=t[i].l&&t[i].r<=r) return t[i].val;
return query(t[i].lc,l,r)+query(t[i].rc,l,r);
}
int mn(int a, int b) {
t[++cnt] = node(t[a].l,t[b].r,t[a].val+t[b].val,a,b);
return cnt;
}
int upd(int i, int pos) {
if(t[i].l==t[i].r) {
t[++cnt] = node(pos);
return cnt;
}
if(pos<t[t[i].rc].l)
return mn(upd(t[i].lc,pos),t[i].rc);
return mn(t[i].lc, upd(t[i].rc, pos));
}
int build(int l, int r){
if(l==r) return t[++cnt]=node(l,l,0,0,0),cnt;
return mn(build(l,l+r>>1),build(l+r+2>>1,r));
}
int order[2][MXN], times[4][MXN], cntx, p[MXN], tb[2][20][MXN], cnty;
int abp(int n) {
return (p[n]==n)?n:(p[n]=abp(p[n]));
}
VI adj[4][MXN];
void dfs1(int n) {
order[0][times[0][n]=++cntx] = n;
for(auto i: adj[0][n])
dfs1(i);
times[2][n] = cntx;
}
void dfs2(int n) {
order[1][times[1][n]=++cntx] = n;
for(auto i: adj[1][n])
dfs2(i);
times[3][n] = cntx;
}
VI rt;
VI check_validity(int N,VI X,VI Y,VI s,VI e,VI l,VI r){
VI ans;
for(int i = 0; i < X.size(); i++) {
if(X[i] < Y[i])
adj[2][X[i]].pb(Y[i]),
adj[3][Y[i]].pb(X[i]);
else
adj[3][X[i]].pb(Y[i]),
adj[2][Y[i]].pb(X[i]);
}
iota(p, p+MXN, 0);
for(int i = N; i--;) {
for(auto j: adj[2][i]) {
if(abp(j)!=i) {
adj[0][i].pb(p[j]);
tb[0][0][p[j]] = i;
p[p[j]]=i;
}
}
}
iota(p, p+MXN, 0);
for(int i = 0; i < N; i++) {
for(auto j: adj[3][i]) {
if(abp(j)!=i) {
adj[1][i].pb(p[j]);
tb[1][0][p[j]] = i;
p[p[j]]=i;
}
}
}
tb[1][0][N-1] = tb[1][0][N] = N;
for(int i = 1; i < 20; i++)
for(int j = 0; j < 2*N; j++)
tb[0][i][j] = tb[0][i-1][tb[0][i-1][j]], tb[1][i][j] = tb[1][i-1][tb[1][i-1][j]];
dfs1(0);
cntx=0;
dfs2(N-1);
rt.pb(build(1,N));
for(int i = 1; i <= N; i++) {
rt.pb(upd(rt.back(), times[1][order[0][i]]));
}
for(int i = 0; i < s.size(); i++) {
int a = s[i], b = e[i], c = l[i], d = r[i];
for(int i = 20; i--;) {
if(tb[0][i][a]>=c)
a = tb[0][i][a];
if(tb[1][i][b]<=d)
b = tb[1][i][b];
}
int A,B,C,D;
A = times[0][a];
B = times[2][a];
C = times[1][b];
D = times[3][b];
ans.pb((bool)(query(rt[B], C, D) - query(rt[A-1],C,D)));
}
return ans;
}
Compilation message
werewolf.cpp: In function 'int build(int, int)':
werewolf.cpp:34:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | return mn(build(l,l+r>>1),build(l+r+2>>1,r));
| ~^~
werewolf.cpp:34:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | return mn(build(l,l+r>>1),build(l+r+2>>1,r));
| ~~~^~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
werewolf.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
157208 KB |
Output is correct |
2 |
Correct |
61 ms |
157200 KB |
Output is correct |
3 |
Correct |
60 ms |
157196 KB |
Output is correct |
4 |
Correct |
57 ms |
157140 KB |
Output is correct |
5 |
Correct |
57 ms |
157232 KB |
Output is correct |
6 |
Correct |
59 ms |
157164 KB |
Output is correct |
7 |
Correct |
65 ms |
157164 KB |
Output is correct |
8 |
Correct |
57 ms |
157132 KB |
Output is correct |
9 |
Correct |
56 ms |
157252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
157208 KB |
Output is correct |
2 |
Correct |
61 ms |
157200 KB |
Output is correct |
3 |
Correct |
60 ms |
157196 KB |
Output is correct |
4 |
Correct |
57 ms |
157140 KB |
Output is correct |
5 |
Correct |
57 ms |
157232 KB |
Output is correct |
6 |
Correct |
59 ms |
157164 KB |
Output is correct |
7 |
Correct |
65 ms |
157164 KB |
Output is correct |
8 |
Correct |
57 ms |
157132 KB |
Output is correct |
9 |
Correct |
56 ms |
157252 KB |
Output is correct |
10 |
Correct |
59 ms |
158764 KB |
Output is correct |
11 |
Correct |
69 ms |
158664 KB |
Output is correct |
12 |
Correct |
57 ms |
158660 KB |
Output is correct |
13 |
Correct |
60 ms |
158828 KB |
Output is correct |
14 |
Correct |
61 ms |
158920 KB |
Output is correct |
15 |
Correct |
59 ms |
158824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1181 ms |
259516 KB |
Output is correct |
2 |
Correct |
1250 ms |
263072 KB |
Output is correct |
3 |
Correct |
1117 ms |
260632 KB |
Output is correct |
4 |
Correct |
1060 ms |
259676 KB |
Output is correct |
5 |
Correct |
1039 ms |
259684 KB |
Output is correct |
6 |
Correct |
1087 ms |
259672 KB |
Output is correct |
7 |
Correct |
940 ms |
259688 KB |
Output is correct |
8 |
Correct |
912 ms |
263164 KB |
Output is correct |
9 |
Correct |
633 ms |
260648 KB |
Output is correct |
10 |
Correct |
422 ms |
259764 KB |
Output is correct |
11 |
Correct |
465 ms |
259636 KB |
Output is correct |
12 |
Correct |
531 ms |
259576 KB |
Output is correct |
13 |
Correct |
985 ms |
272552 KB |
Output is correct |
14 |
Correct |
962 ms |
272536 KB |
Output is correct |
15 |
Correct |
1051 ms |
272628 KB |
Output is correct |
16 |
Correct |
1046 ms |
272536 KB |
Output is correct |
17 |
Correct |
929 ms |
259560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
157208 KB |
Output is correct |
2 |
Correct |
61 ms |
157200 KB |
Output is correct |
3 |
Correct |
60 ms |
157196 KB |
Output is correct |
4 |
Correct |
57 ms |
157140 KB |
Output is correct |
5 |
Correct |
57 ms |
157232 KB |
Output is correct |
6 |
Correct |
59 ms |
157164 KB |
Output is correct |
7 |
Correct |
65 ms |
157164 KB |
Output is correct |
8 |
Correct |
57 ms |
157132 KB |
Output is correct |
9 |
Correct |
56 ms |
157252 KB |
Output is correct |
10 |
Correct |
59 ms |
158764 KB |
Output is correct |
11 |
Correct |
69 ms |
158664 KB |
Output is correct |
12 |
Correct |
57 ms |
158660 KB |
Output is correct |
13 |
Correct |
60 ms |
158828 KB |
Output is correct |
14 |
Correct |
61 ms |
158920 KB |
Output is correct |
15 |
Correct |
59 ms |
158824 KB |
Output is correct |
16 |
Correct |
1181 ms |
259516 KB |
Output is correct |
17 |
Correct |
1250 ms |
263072 KB |
Output is correct |
18 |
Correct |
1117 ms |
260632 KB |
Output is correct |
19 |
Correct |
1060 ms |
259676 KB |
Output is correct |
20 |
Correct |
1039 ms |
259684 KB |
Output is correct |
21 |
Correct |
1087 ms |
259672 KB |
Output is correct |
22 |
Correct |
940 ms |
259688 KB |
Output is correct |
23 |
Correct |
912 ms |
263164 KB |
Output is correct |
24 |
Correct |
633 ms |
260648 KB |
Output is correct |
25 |
Correct |
422 ms |
259764 KB |
Output is correct |
26 |
Correct |
465 ms |
259636 KB |
Output is correct |
27 |
Correct |
531 ms |
259576 KB |
Output is correct |
28 |
Correct |
985 ms |
272552 KB |
Output is correct |
29 |
Correct |
962 ms |
272536 KB |
Output is correct |
30 |
Correct |
1051 ms |
272628 KB |
Output is correct |
31 |
Correct |
1046 ms |
272536 KB |
Output is correct |
32 |
Correct |
929 ms |
259560 KB |
Output is correct |
33 |
Correct |
1508 ms |
259268 KB |
Output is correct |
34 |
Correct |
305 ms |
188100 KB |
Output is correct |
35 |
Correct |
1808 ms |
262260 KB |
Output is correct |
36 |
Correct |
1463 ms |
260276 KB |
Output is correct |
37 |
Correct |
1786 ms |
261200 KB |
Output is correct |
38 |
Correct |
1546 ms |
261020 KB |
Output is correct |
39 |
Correct |
1533 ms |
271220 KB |
Output is correct |
40 |
Correct |
881 ms |
271228 KB |
Output is correct |
41 |
Correct |
1024 ms |
260648 KB |
Output is correct |
42 |
Correct |
472 ms |
260324 KB |
Output is correct |
43 |
Correct |
1567 ms |
268720 KB |
Output is correct |
44 |
Correct |
1561 ms |
261280 KB |
Output is correct |
45 |
Correct |
829 ms |
271664 KB |
Output is correct |
46 |
Correct |
1077 ms |
271252 KB |
Output is correct |
47 |
Correct |
966 ms |
272704 KB |
Output is correct |
48 |
Correct |
998 ms |
272608 KB |
Output is correct |
49 |
Correct |
959 ms |
272768 KB |
Output is correct |
50 |
Correct |
1054 ms |
272648 KB |
Output is correct |
51 |
Correct |
602 ms |
270656 KB |
Output is correct |
52 |
Correct |
653 ms |
270564 KB |
Output is correct |