#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
//0: human can reach (max) 1: werewolf (min)
const int N=600050;
int n,ch[2][2][N],val[2][N],par[2][N],pt[2],lift[2][20][N],sz[2][N],tim[2],pre[2][N],bit[N];
int u,v,l0,r0,l1,r1;
vector<pair<int,pair<int,int>>> srt[2];
vector<pair<pair<int,int>,pair<int,int>>> op;
int find(int id,int nde){
return par[id][nde]==nde?nde:par[id][nde]=find(id,par[id][nde]);
}
void dfs(int id,int nde,int par){
lift[id][0][nde]=par;
for (int i=1;i<=19;i++) lift[id][i][nde]=lift[id][i-1][lift[id][i-1][nde]];
pre[id][nde]=++tim[id];
sz[id][nde]=1;
if (nde>=n){
dfs(id,ch[id][0][nde],nde);
dfs(id,ch[id][1][nde],nde);
sz[id][nde]+=sz[id][ch[id][0][nde]]+sz[id][ch[id][1][nde]];
}
}
void upd(int id,int val){
for (;id<N;id+=id&-id) bit[id]+=val;
}
int query(int id){
int ret=0;
for (;id;id-=id&-id) ret+=bit[id];
return ret;
}
vector<int> check_validity(int N, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r) {
n=N;
int q=s.size(),m=x.size();
vector<int> ans(q);
for (int i=0;i<m;i++){
srt[0].push_back({min(x[i],y[i]),{x[i],y[i]}});
srt[1].push_back({max(x[i],y[i]),{x[i],y[i]}});
}
sort(srt[0].begin(),srt[0].end(),greater<pair<int,pair<int,int>>>());
sort(srt[1].begin(),srt[1].end());
for (int i=0;i<2*n;i++) par[0][i]=par[1][i]=i;
pt[0]=n,pt[1]=n;
for (auto i:srt[0]){
if (find(0,i.second.first)==find(0,i.second.second)) continue;
ch[0][0][pt[0]]=find(0,i.second.first);
ch[0][1][pt[0]]=find(0,i.second.second);
par[0][find(0,i.second.first)]=pt[0];
par[0][find(0,i.second.second)]=pt[0];
val[0][pt[0]]=i.first;
pt[0]++;
}
for (auto i:srt[1]){
if (find(1,i.second.first)==find(1,i.second.second)) continue;
ch[1][0][pt[1]]=find(1,i.second.first);
ch[1][1][pt[1]]=find(1,i.second.second);
par[1][find(1,i.second.first)]=pt[1];
par[1][find(1,i.second.second)]=pt[1];
val[1][pt[1]]=i.first;
pt[1]++;
}
dfs(0,2*n-2,2*n-2);
dfs(1,2*n-2,2*n-2);
for (int i=0;i<n;i++) op.push_back({{pre[0][i],pre[1][i]},{1,1}});
for (int i=0;i<q;i++){
u=s[i],v=e[i];
for (int j=19;j>=0;j--) if (val[0][lift[0][j][u]]>=l[i]) u=lift[0][j][u];
for (int j=19;j>=0;j--) if (val[1][lift[1][j][v]]<=r[i]) v=lift[1][j][v];
l0=pre[0][u],r0=pre[0][u]+sz[0][u]-1;
l1=pre[1][v],r1=pre[1][v]+sz[1][v]-1;
op.push_back({{r0,r1},{2,i*2}});
op.push_back({{r0,l1-1},{2,i*2+1}});
op.push_back({{l0-1,r1},{2,i*2+1}});
op.push_back({{l0-1,l1-1},{2,i*2}});
}
sort(op.begin(),op.end());
for (auto i:op){
if (i.second.first==1){
upd(i.first.second,1);
}else if (i.second.first==2){
if (i.second.second%2) ans[i.second.second/2]-=query(i.first.second);
else ans[i.second.second/2]+=query(i.first.second);
}else{
upd(i.first.second,-1);
}
}
for (int &i:ans) i=!!i;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
820 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
820 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
824 KB |
Output is correct |
10 |
Correct |
7 ms |
2752 KB |
Output is correct |
11 |
Correct |
9 ms |
2772 KB |
Output is correct |
12 |
Correct |
7 ms |
2612 KB |
Output is correct |
13 |
Correct |
8 ms |
2880 KB |
Output is correct |
14 |
Correct |
7 ms |
2792 KB |
Output is correct |
15 |
Correct |
8 ms |
2932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
767 ms |
119872 KB |
Output is correct |
2 |
Correct |
725 ms |
127692 KB |
Output is correct |
3 |
Correct |
761 ms |
122612 KB |
Output is correct |
4 |
Correct |
664 ms |
120392 KB |
Output is correct |
5 |
Correct |
660 ms |
120284 KB |
Output is correct |
6 |
Correct |
689 ms |
119976 KB |
Output is correct |
7 |
Correct |
672 ms |
120000 KB |
Output is correct |
8 |
Correct |
683 ms |
127628 KB |
Output is correct |
9 |
Correct |
516 ms |
122572 KB |
Output is correct |
10 |
Correct |
456 ms |
120296 KB |
Output is correct |
11 |
Correct |
505 ms |
120240 KB |
Output is correct |
12 |
Correct |
550 ms |
120032 KB |
Output is correct |
13 |
Correct |
781 ms |
127752 KB |
Output is correct |
14 |
Correct |
797 ms |
127636 KB |
Output is correct |
15 |
Correct |
809 ms |
127720 KB |
Output is correct |
16 |
Correct |
813 ms |
127648 KB |
Output is correct |
17 |
Correct |
683 ms |
119832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
820 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
824 KB |
Output is correct |
10 |
Correct |
7 ms |
2752 KB |
Output is correct |
11 |
Correct |
9 ms |
2772 KB |
Output is correct |
12 |
Correct |
7 ms |
2612 KB |
Output is correct |
13 |
Correct |
8 ms |
2880 KB |
Output is correct |
14 |
Correct |
7 ms |
2792 KB |
Output is correct |
15 |
Correct |
8 ms |
2932 KB |
Output is correct |
16 |
Correct |
767 ms |
119872 KB |
Output is correct |
17 |
Correct |
725 ms |
127692 KB |
Output is correct |
18 |
Correct |
761 ms |
122612 KB |
Output is correct |
19 |
Correct |
664 ms |
120392 KB |
Output is correct |
20 |
Correct |
660 ms |
120284 KB |
Output is correct |
21 |
Correct |
689 ms |
119976 KB |
Output is correct |
22 |
Correct |
672 ms |
120000 KB |
Output is correct |
23 |
Correct |
683 ms |
127628 KB |
Output is correct |
24 |
Correct |
516 ms |
122572 KB |
Output is correct |
25 |
Correct |
456 ms |
120296 KB |
Output is correct |
26 |
Correct |
505 ms |
120240 KB |
Output is correct |
27 |
Correct |
550 ms |
120032 KB |
Output is correct |
28 |
Correct |
781 ms |
127752 KB |
Output is correct |
29 |
Correct |
797 ms |
127636 KB |
Output is correct |
30 |
Correct |
809 ms |
127720 KB |
Output is correct |
31 |
Correct |
813 ms |
127648 KB |
Output is correct |
32 |
Correct |
683 ms |
119832 KB |
Output is correct |
33 |
Correct |
775 ms |
121776 KB |
Output is correct |
34 |
Correct |
438 ms |
56184 KB |
Output is correct |
35 |
Correct |
904 ms |
127292 KB |
Output is correct |
36 |
Correct |
791 ms |
121244 KB |
Output is correct |
37 |
Correct |
854 ms |
125844 KB |
Output is correct |
38 |
Correct |
840 ms |
122472 KB |
Output is correct |
39 |
Correct |
851 ms |
135572 KB |
Output is correct |
40 |
Correct |
886 ms |
136692 KB |
Output is correct |
41 |
Correct |
705 ms |
124776 KB |
Output is correct |
42 |
Correct |
594 ms |
121248 KB |
Output is correct |
43 |
Correct |
809 ms |
135872 KB |
Output is correct |
44 |
Correct |
808 ms |
125828 KB |
Output is correct |
45 |
Correct |
653 ms |
136024 KB |
Output is correct |
46 |
Correct |
736 ms |
135620 KB |
Output is correct |
47 |
Correct |
775 ms |
127916 KB |
Output is correct |
48 |
Correct |
795 ms |
127656 KB |
Output is correct |
49 |
Correct |
800 ms |
127940 KB |
Output is correct |
50 |
Correct |
825 ms |
127808 KB |
Output is correct |
51 |
Correct |
813 ms |
137144 KB |
Output is correct |
52 |
Correct |
818 ms |
137060 KB |
Output is correct |