#include<bits/stdc++.h>
#include "werewolf.h"
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()
struct node
{
ll min,max;
};
node seg[800000];
ll arr[200000];
void build(int l,int r,int idx)
{
if(l==r)
{
seg[idx]={arr[l],arr[l]};
return ;
}
build(l,(l+r)/2,idx*2);
build((l+r)/2+1,r,idx*2+1);
seg[idx].min=min(seg[idx*2].min,seg[idx*2+1].min);
seg[idx].max=max(seg[idx*2].max,seg[idx*2+1].max);
}
node query(int L,int R,int l,int r,int idx)
{
if(l>R || r<L)
return {INF,0};
if(L<=l && r<=R)
return seg[idx];
node p1=query(L,R,l,(l+r)/2,idx*2);
node p2=query(L,R,(l+r)/2+1,r,idx*2+1);
return {min(p1.min,p2.min),max(p1.max,p2.max)};
}
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) {
int Q = S.size();
ll m=X.size();
vector<vector<int>>g;
g.assign(n,vector<int>());
for(int i=0;i<m;i++)
{
g[X[i]].pb(Y[i]);
g[Y[i]].pb(X[i]);
}
ll start=0;
for(int i=0;i<n;i++)
if(g[i].size()==1)
{
start=i;
break;
}
ll dic[n];
vector<int>ans;
vector<bool>vis(n,0);
queue<int>q;
q.push(start);
ll idx=0;
vis[start]=1;
while(!q.empty())
{
ll curr=q.front();
dic[curr]=idx;
arr[idx]=curr;
idx++;
q.pop();
for(auto x:g[curr])
if(!vis[x])
{
vis[x]=1;
q.push(x);
}
}
build(0,n-1,1);
for(int i=0;i<Q;i++)
{
ll l=dic[S[i]],r=dic[E[i]];
if(l<r)
{
bool tf=true;
while(l<r)
{
ll mid=(l+r)/2;
node left=query(l,mid,0,n-1,1);
node right=query(mid+1,r,0,n-1,1);
if(left.min<L[i] && right.max>R[i])
{
tf=0;
break;
}
if(left.min<L[i])
{
r=mid;
continue;
}
if(right.max>R[i])
{
l=mid+1;
continue;
}
if(arr[mid]<=R[i] && arr[mid]>=L[i] || arr[mid+1]<=R[i] && arr[mid+1]>=L[i])
break;
else
{
tf=0;
break;
}
}
ans.pb(tf);
continue;
}
bool tf=true;
swap(l,r);
while(l<r)
{
ll mid=(l+r)/2;
node left=query(l,mid,0,n-1,1);
node right=query(mid+1,r,0,n-1,1);
if(left.max>R[i] && right.min<L[i])
{
tf=0;
break;
}
if(left.max>R[i])
{
r=mid;
continue;
}
if(right.min<L[i])
{
l=mid+1;
continue;
}
if(dic[mid]<=R[i] && dic[mid]>=L[i] || dic[mid+1]<=R[i] && dic[mid+1]>=L[i])
break;
else
{
tf=0;
break;
}
}
ans.pb(tf);
}
return ans;
}
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:134:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
134 | if(arr[mid]<=R[i] && arr[mid]>=L[i] || arr[mid+1]<=R[i] && arr[mid+1]>=L[i])
werewolf.cpp:173:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
173 | if(dic[mid]<=R[i] && dic[mid]>=L[i] || dic[mid+1]<=R[i] && dic[mid+1]>=L[i])
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
300 ms |
34124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |