#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
int n,m,q,p[200001],node[200001],l[400001],r[400001],par[400001][20],val[400001],id,x[200001],idx,order[200001];
int lx[200001],rx[200001],ly[200001],ry[200001];
vector <int> ke[400001],a,st[800001];
vector <pii> edge;
int f(int i){
return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int i, int j){
int w=i;
i=f(i);
j=f(j);
if (i==j)
return;
id++;
val[id]=w;
ke[id].push_back(node[i]);
ke[id].push_back(node[j]);
node[i]=id;
p[j]=i;
}
void dfs(int u){
if (u<n){
l[u]=r[u]=x[u]=idx;
idx++;
return;
}
l[u]=1e9,r[u]=0;
for (int v:ke[u]){
par[v+1][0]=u+1;
for (int i=1;i<20;i++)
par[v+1][i]=par[par[v+1][i-1]][i-1];
dfs(v);
l[u]=min(l[u],l[v]);
r[u]=max(r[u],r[v]);
}
}
void build(int node, int l, int r){
if (l==r){
st[node]={x[order[l]]};
return;
}
int mid=(l+r)>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
int i=0,j=0;
while (i<st[node<<1].size()||j<st[node<<1|1].size()){
if (i>=st[node<<1].size()){
st[node].push_back(st[node<<1|1][j]);
j++;
continue;
}
if (j>=st[node<<1|1].size()){
st[node].push_back(st[node<<1][i]);
i++;
continue;
}
if (st[node<<1][i]<st[node<<1|1][j]){
st[node].push_back(st[node<<1][i]);
i++;
continue;
}
st[node].push_back(st[node<<1|1][j]);
j++;
continue;
}
}
int get(int node, int l, int r, int u, int v, int y){
if (l>v||r<u||l>r||u>v)
return 0;
if (l>=u&&r<=v)
return upper_bound(st[node].begin(),st[node].end(),y)-st[node].begin();
int mid=(l+r)>>1;
return get(node<<1,l,mid,u,v,y)+get(node<<1|1,mid+1,r,u,v,y);
}
bool get(int l, int r, int x, int y){
return get(1,0,n-1,l,r,y)-get(1,0,n-1,l,r,x-1);
}
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;
m=X.size();
q=S.size();
a.assign(q,0);
iota(p,p+n,0);
iota(node,node+n,0);
id=n;
for (int i=0;i<m;i++)
edge.push_back({min(X[i],Y[i]),max(X[i],Y[i])});
sort(edge.begin(),edge.end());
for (int i=m-1;i>=0;i--)
unite(edge[i].first,edge[i].second);
dfs(id);
for (int i=0;i<q;i++){
int u=S[i]+1;
for (int j=19;j>=0;j--)
if (par[u][j]&&val[par[u][j]-1]>=L[i])
u=par[u][j];
lx[i]=l[u-1];
rx[i]=r[u-1];
}
for (int i=0;i<n;i++){
order[x[i]]=i;
node[i]=p[i]=i;
}
for (int i=0;i<=id;i++)
ke[i].clear();
id=n;
idx=0;
for (int i=0;i<m;i++)
swap(edge[i].first,edge[i].second);
sort(edge.begin(),edge.end());
for (int i=0;i<m;i++)
unite(edge[i].first,edge[i].second);
dfs(id);
for (int i=0;i<q;i++){
int u=E[i]+1;
for (int j=19;j>=0;j--)
if (par[u][j]&&val[par[u][j]-1]<=R[i])
u=par[u][j];
ly[i]=l[u-1];
ry[i]=r[u-1];
}
build(1,0,n-1);
for (int i=0;i<q;i++)
a[i]=get(lx[i],rx[i],ly[i],ry[i]);
return a;
}
Compilation message
werewolf.cpp: In function 'void build(int, int, int)':
werewolf.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while (i<st[node<<1].size()||j<st[node<<1|1].size()){
| ~^~~~~~~~~~~~~~~~~~~
werewolf.cpp:50:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while (i<st[node<<1].size()||j<st[node<<1|1].size()){
| ~^~~~~~~~~~~~~~~~~~~~~
werewolf.cpp:51:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if (i>=st[node<<1].size()){
| ~^~~~~~~~~~~~~~~~~~~~
werewolf.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if (j>=st[node<<1|1].size()){
| ~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
41560 KB |
Output is correct |
2 |
Correct |
8 ms |
41816 KB |
Output is correct |
3 |
Correct |
8 ms |
41560 KB |
Output is correct |
4 |
Correct |
8 ms |
41560 KB |
Output is correct |
5 |
Correct |
10 ms |
41560 KB |
Output is correct |
6 |
Correct |
9 ms |
41624 KB |
Output is correct |
7 |
Correct |
8 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
41560 KB |
Output is correct |
2 |
Correct |
8 ms |
41816 KB |
Output is correct |
3 |
Correct |
8 ms |
41560 KB |
Output is correct |
4 |
Correct |
8 ms |
41560 KB |
Output is correct |
5 |
Correct |
10 ms |
41560 KB |
Output is correct |
6 |
Correct |
9 ms |
41624 KB |
Output is correct |
7 |
Correct |
8 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41972 KB |
Output is correct |
10 |
Correct |
15 ms |
42328 KB |
Output is correct |
11 |
Correct |
17 ms |
42328 KB |
Output is correct |
12 |
Correct |
14 ms |
42328 KB |
Output is correct |
13 |
Correct |
14 ms |
42584 KB |
Output is correct |
14 |
Correct |
13 ms |
42584 KB |
Output is correct |
15 |
Correct |
16 ms |
42428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
649 ms |
117348 KB |
Output is correct |
2 |
Correct |
822 ms |
133056 KB |
Output is correct |
3 |
Correct |
762 ms |
127936 KB |
Output is correct |
4 |
Correct |
647 ms |
125660 KB |
Output is correct |
5 |
Correct |
642 ms |
125468 KB |
Output is correct |
6 |
Correct |
635 ms |
125120 KB |
Output is correct |
7 |
Correct |
615 ms |
125076 KB |
Output is correct |
8 |
Correct |
799 ms |
132812 KB |
Output is correct |
9 |
Correct |
531 ms |
127864 KB |
Output is correct |
10 |
Correct |
567 ms |
125712 KB |
Output is correct |
11 |
Correct |
570 ms |
125464 KB |
Output is correct |
12 |
Correct |
468 ms |
125432 KB |
Output is correct |
13 |
Correct |
704 ms |
132920 KB |
Output is correct |
14 |
Correct |
669 ms |
132840 KB |
Output is correct |
15 |
Correct |
650 ms |
132692 KB |
Output is correct |
16 |
Correct |
671 ms |
132820 KB |
Output is correct |
17 |
Correct |
647 ms |
124864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
41560 KB |
Output is correct |
2 |
Correct |
8 ms |
41816 KB |
Output is correct |
3 |
Correct |
8 ms |
41560 KB |
Output is correct |
4 |
Correct |
8 ms |
41560 KB |
Output is correct |
5 |
Correct |
10 ms |
41560 KB |
Output is correct |
6 |
Correct |
9 ms |
41624 KB |
Output is correct |
7 |
Correct |
8 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41972 KB |
Output is correct |
10 |
Correct |
15 ms |
42328 KB |
Output is correct |
11 |
Correct |
17 ms |
42328 KB |
Output is correct |
12 |
Correct |
14 ms |
42328 KB |
Output is correct |
13 |
Correct |
14 ms |
42584 KB |
Output is correct |
14 |
Correct |
13 ms |
42584 KB |
Output is correct |
15 |
Correct |
16 ms |
42428 KB |
Output is correct |
16 |
Correct |
649 ms |
117348 KB |
Output is correct |
17 |
Correct |
822 ms |
133056 KB |
Output is correct |
18 |
Correct |
762 ms |
127936 KB |
Output is correct |
19 |
Correct |
647 ms |
125660 KB |
Output is correct |
20 |
Correct |
642 ms |
125468 KB |
Output is correct |
21 |
Correct |
635 ms |
125120 KB |
Output is correct |
22 |
Correct |
615 ms |
125076 KB |
Output is correct |
23 |
Correct |
799 ms |
132812 KB |
Output is correct |
24 |
Correct |
531 ms |
127864 KB |
Output is correct |
25 |
Correct |
567 ms |
125712 KB |
Output is correct |
26 |
Correct |
570 ms |
125464 KB |
Output is correct |
27 |
Correct |
468 ms |
125432 KB |
Output is correct |
28 |
Correct |
704 ms |
132920 KB |
Output is correct |
29 |
Correct |
669 ms |
132840 KB |
Output is correct |
30 |
Correct |
650 ms |
132692 KB |
Output is correct |
31 |
Correct |
671 ms |
132820 KB |
Output is correct |
32 |
Correct |
647 ms |
124864 KB |
Output is correct |
33 |
Correct |
814 ms |
127168 KB |
Output is correct |
34 |
Correct |
339 ms |
70712 KB |
Output is correct |
35 |
Correct |
1032 ms |
132468 KB |
Output is correct |
36 |
Correct |
821 ms |
126592 KB |
Output is correct |
37 |
Correct |
1040 ms |
131264 KB |
Output is correct |
38 |
Correct |
863 ms |
127680 KB |
Output is correct |
39 |
Correct |
684 ms |
140980 KB |
Output is correct |
40 |
Correct |
804 ms |
137316 KB |
Output is correct |
41 |
Correct |
871 ms |
129984 KB |
Output is correct |
42 |
Correct |
643 ms |
126404 KB |
Output is correct |
43 |
Correct |
1203 ms |
137828 KB |
Output is correct |
44 |
Correct |
905 ms |
130976 KB |
Output is correct |
45 |
Correct |
718 ms |
141052 KB |
Output is correct |
46 |
Correct |
851 ms |
141092 KB |
Output is correct |
47 |
Correct |
648 ms |
133260 KB |
Output is correct |
48 |
Correct |
683 ms |
133116 KB |
Output is correct |
49 |
Correct |
685 ms |
133164 KB |
Output is correct |
50 |
Correct |
625 ms |
132868 KB |
Output is correct |
51 |
Correct |
733 ms |
137208 KB |
Output is correct |
52 |
Correct |
723 ms |
137400 KB |
Output is correct |