#pragma GCC optimize("O3")
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
#define INF (int)(1e9)
vector<vector<int> > vec;
int A[200005],idx=0,to_id[200005];
ii st[800005];
bool vis[200005];
void build(int node,int l,int r){
if(l==r){
st[node]=ii(A[l],A[l]);
return ;
}
int med=((l+r)>>1);
build(node<<1,l,med),build((node<<1)+1,med+1,r);
st[node].fi=min(st[node<<1].fi,st[(node<<1)+1].fi);
st[node].se=max(st[node<<1].se,st[(node<<1)+1].se);
}
ii query(int node,int l,int r,int i,int j){
if(l>j||r<i)
return ii(INF,-1);
if(l>=i&&r<=j)
return st[node];
int med=((l+r)>>1);
ii q1=query(node<<1,l,med,i,j),q2=query((node<<1)+1,med+1,r,i,j);
return ii(min(q1.fi,q2.fi),max(q1.se,q2.se));
}
int D,LE,RE;
int vis_dfs[5001],v=1;
int dp[101][2][2];
int dfs(int node,int changed,int trans){
//cerr<<node<<" "<<changed<<" "<<trans<<"\n";
if(node==D&&!changed&&trans)return 1;
if(node==D)return changed;
if(dp[node][changed][trans]!=-1)
return dp[node][changed][trans];
vis_dfs[node]=1;
int ans=0;
for(auto child:vec[node]){
if(vis_dfs[child]==1)continue;
if(child<LE&&!changed){
if(trans)ans|=dfs(child,1,0);
else continue;
}
if(child>RE&&changed)continue;
if(child<=RE&&changed)ans|=dfs(child,1,0);
if(child>=LE&&!changed)ans|=dfs(child,0,((child>=LE&&child<=RE)));
if(trans&&child<=RE&&!changed)ans|=dfs(child,1,0);
if(ans){vis_dfs[node]=0; return dp[node][changed][trans]=1;}
}
vis_dfs[node]=0;
return dp[node][changed][trans]=0;
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y,
vector<int> S, vector<int> E,
vector<int> L, vector<int> R) {
int M = X.size();
int Q = S.size();
vec.resize(N);
for (int i = 0; i < X.size(); ++i)
{
vec[X[i]].pb(Y[i]);
vec[Y[i]].pb(X[i]);
}
if(N<=100||M<=200||Q<=100){
vector<int> res(Q);
for (int i =0; i < Q; ++i)
{
memset(dp,-1,sizeof dp);
D=E[i];
LE=L[i],RE=R[i];
//cerr<<S[i]<<","<<E[i]<<"\n";
//cerr<<L[i]<<","<<R[i]<<"\n";
if(S[i]<LE||E[i]>RE)res[i]=0;
else res[i]=dfs(S[i],0,(S[i]>=L[i]&&S[i]<=R[i]));
}
return res;
}
int start=0;
for (int i = 0; i < N; ++i)
if(vec[i].size()==1){
start=i;
break;
}
queue<int> AA;
AA.push(start);
vis[start]=1;
while(!AA.empty()){
int front=AA.front();
A[idx]=front;
to_id[front]=idx++;
AA.pop();
for(auto child:vec[front])
if(!vis[child])
vis[child]=1,AA.push(child);
}
build(1,0,idx);
vector<int> res(Q);
fill(res.begin(),res.end(),0);
for (int i = 0; i < Q; ++i) {
if(S[i]==E[i]){
if(S[i]<=R[i]&&S[i]>=L[i])res[i]=1;
else res[i]=0;
continue;
}
if(S[i]<L[i]||E[i]>R[i]){res[i]=0;continue;}
if(to_id[S[i]]<to_id[E[i]]){
int l=to_id[S[i]],r=to_id[E[i]];
while(l<=r){
int med=((l+r)>>1);
if(med!=to_id[S[i]]){
ii q=query(1,0,idx,to_id[S[i]],med-1);
if(q.fi<L[i]){r=med-1;continue;}
}
if(med!=to_id[E[i]]){
ii q=query(1,0,idx,med+1,to_id[E[i]]);
if(q.se>R[i]){l=med+1;continue;}
}
if(A[med]<=R[i]&&A[med]>=L[i])res[i]=1;
else if(A[med]>=L[i]){
if(A[med]==(E[i]))res[i]=0;
else if(A[med+1]<=R[i]&&A[med+1]>=L[i])res[i]=1;
else res[i]=0;
}
else if(A[med]<=R[i]){
if(A[med]==S[i])res[i]=0;
else if(A[med-1]<=R[i]&&A[med-1]>=L[i])res[i]=1;
else res[i]=0;
}
break;
}
}
else{
int l=to_id[E[i]],r=to_id[S[i]];
while(l<=r){
int med=((l+r)>>1);
if(med!=to_id[E[i]]){
ii q=query(1,0,idx,to_id[E[i]],med-1);
if(q.se>R[i]){r=med-1;continue;}
}
if(med!=to_id[S[i]]){
ii q=query(1,0,idx,med+1,to_id[S[i]]);
if(q.fi<L[i]){l=med+1;continue;}
}
if(A[med]<=R[i]&&A[med]>=L[i])res[i]=1;
else if(A[med]<=R[i]){
if(A[med]==(S[i]))res[i]=0;
else if(A[med+1]<=R[i]&&A[med+1]>=L[i])res[i]=1;
else res[i]=0;
}
else if(A[med]>=L[i]){
if(A[med]==E[i])res[i]=0;
else if(A[med-1]<=R[i]&&A[med-1]>=L[i])res[i]=1;
else res[i]=0;
}
break;
}
}}
return res;
}
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:68:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < X.size(); ++i)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
13 ms |
888 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1359 ms |
27412 KB |
Output is correct |
2 |
Correct |
521 ms |
27384 KB |
Output is correct |
3 |
Correct |
554 ms |
27424 KB |
Output is correct |
4 |
Correct |
878 ms |
27484 KB |
Output is correct |
5 |
Correct |
1093 ms |
27436 KB |
Output is correct |
6 |
Correct |
1616 ms |
27360 KB |
Output is correct |
7 |
Correct |
1662 ms |
27640 KB |
Output is correct |
8 |
Correct |
514 ms |
27384 KB |
Output is correct |
9 |
Correct |
524 ms |
27412 KB |
Output is correct |
10 |
Correct |
599 ms |
27352 KB |
Output is correct |
11 |
Correct |
882 ms |
27484 KB |
Output is correct |
12 |
Correct |
1228 ms |
27512 KB |
Output is correct |
13 |
Correct |
1263 ms |
27512 KB |
Output is correct |
14 |
Correct |
1210 ms |
27488 KB |
Output is correct |
15 |
Correct |
1198 ms |
27516 KB |
Output is correct |
16 |
Correct |
1193 ms |
27464 KB |
Output is correct |
17 |
Correct |
1746 ms |
27384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
13 ms |
888 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |