#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[200100];
int stbmx[200100][20],stbmn[200100][20];
int CC;
int pos[200100];
void dfs(int n,int p) {
stbmn[pos[n]=++CC][0]=n;
stbmx[CC][0]=n;
for(auto i:adj[n])
if(i-p) dfs(i,n);
}
int qrymx(int l,int r){
int x=31-__builtin_clz(r-l+1);
return max(stbmx[l][x],stbmx[r-(1<<x)+1][x]);
}
int qrymn(int l,int r){
int x=31-__builtin_clz(r-l+1);
return min(stbmn[l][x],stbmn[r-(1<<x)+1][x]);
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,std::vector<int> L, std::vector<int> R) {
for(int i=0;i<X.size();i++)
adj[X[i]].push_back(Y[i]),
adj[Y[i]].push_back(X[i]);
int lef=0;
for(int i=0;i<N;i++)
if(adj[i].size()==1)
lef=i;
dfs(lef,-1);
for(int j=1;j<20;j++) for(int i=0;i<=N-(1<<j);i++)
stbmx[i][j]=max(stbmx[i][j-1],stbmx[i+(1<<j-1)][j-1]),
stbmn[i][j]=min(stbmn[i][j-1],stbmn[i+(1<<j-1)][j-1]);
int Q=S.size();
vector<int>A(Q);
memset(stbmx,1,sizeof stbmx);
memset(stbmn,-1,sizeof stbmn);
for(int i=0;i<Q;i++){
int s=S[i],e=E[i],l=L[i],r=R[i];
s=pos[s];
e=pos[e];
if(s<e) {
for(int i=20;i--;)
if(stbmn[s][i]>=l)
s+=1<<i;
if(s>=e) A[i]=1;
else A[i]=qrymx(s,e)<=r;
} else {
for(int i=20;i--;)
if(stbmx[e][i]<=r)
e+=1<<i;
if(e>=s)A[i]=1;
else A[i]=qrymn(s,e)<=l;
}
}
return A;
}
Compilation message
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:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<X.size();i++)
| ~^~~~~~~~~
werewolf.cpp:33:48: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
33 | stbmx[i][j]=max(stbmx[i][j-1],stbmx[i+(1<<j-1)][j-1]),
| ~^~
werewolf.cpp:34:48: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
34 | stbmn[i][j]=min(stbmn[i][j-1],stbmn[i+(1<<j-1)][j-1]);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
42 ms |
91860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
42 ms |
91860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
180 ms |
127572 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
42 ms |
91860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |