#include "werewolf.h"
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define ld long double
#define F first
#define S second
#define mp make_pair
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=5e5+500;
const ll inf=1e9+900;
ll seg[maxn*4];
ll findMin(ll L,ll R,ll node,ll l,ll r){
if(l<=L && R<=r){
return seg[node];
}
if(r<=L || R<=l)return inf;
ll mid=(L+R)/2;
return min(findMin(L,mid,2*node,l,r),findMin(mid,R,2*node+1,l,r));
}
void update(ll L,ll R,ll node,ll x,ll v){
if(L+1==R){
seg[node]=v;
return;
}
ll mid=(L+R)/2;
if(x<mid){
update(L,mid,2*node,x,v);
}else{
update(mid,R,2*node+1,x,v);
}
seg[node]=min(seg[2*node],seg[2*node+1]);
}
void bild(){
fill(seg,seg+maxn*4,inf);
}
vector<ll> c[2];
ll n,q;
ll kojc1[maxn];
vector<ll> ves[maxn];
vector<ll> findAns(vector<ll> l,vector<ll> r,vector<ll> L,vector<ll> R){
for(ll i=0;i<n;i++){
kojc1[c[1][i]]=i;
}
vector<ll> ans;
ans.resize(q);
for(ll i=0;i<q;i++){
l[i]=max(l[i],0);
r[i]=min(r[i],n);
L[i]=max(L[i],0);
R[i]=min(R[i],n);
if(!(l[i]>=r[i] || L[i]>=R[i])){
ves[l[i]].pb(i);
}
}
bild();
for(ll i=n-1;i>=0;i--){
update(0,n,1,kojc1[c[0][i]],i);
for(auto y:ves[i]){
ll u=findMin(0,n,1,L[y],R[y]);
if(u<r[y]){
ans[y]=1;
}
}
}
return ans;
}
ll m;
vector<ll> ger[maxn];
ll par[maxn];
bool hast[maxn];
vector<ll> tree[2][maxn];
ll st[2][maxn];
ll et[2][maxn];
ll tt=0;
ll cnt=-1;
ll findPar(ll x){
if(par[x]==x)return x;
par[x]=findPar(par[x]);
return par[x];
}
void clearr(){
cnt++;
for(ll i=0;i<maxn;i++){
par[i]=i;
hast[i]=0;
}
}
void add(ll x){
hast[x]=1;
for(auto v:ger[x]){
if(hast[v]){
ll r=findPar(v);
if(r!=x){
par[r]=x;
tree[cnt][x].pb(r);
}
}
}
}
void dfs(ll a,ll b){
c[b].pb(a);
st[b][a]=tt++;
for(auto v:tree[b][a]){
dfs(v,b);
}
et[b][a]=tt;
}
vector<ll> li[maxn];
vector<ll> ri[maxn];
ll lp[maxn];
ll rp[maxn];
vector<int> check_validity(int N,vector<int> X,vector<int> Y,vector<int> S,vector<int> E,vector<int> L,vector<int> R) {
q = S.size();
m=X.size();
n=N;
for(ll i=0;i<m;i++){
ger[X[i]].pb(Y[i]);
ger[Y[i]].pb(X[i]);
}
for(ll i=0;i<q;i++){
li[L[i]].pb(i);
ri[R[i]].pb(i);
}
clearr();
for(ll i=0;i<n;i++){
add(i);
for(auto x:ri[i]){
rp[x]=findPar(E[x]);
}
}
ll rotr=findPar(0);
clearr();
for(ll i=n-1;i>=0;i--){
add(i);
for(auto x:li[i]){
lp[x]=findPar(S[x]);
}
}
ll rotl=findPar(0);
tt=0;
dfs(rotr,0);
tt=0;
dfs(rotl,1);
vector<ll> A,B,a,b;
A.resize(q);B.resize(q);a.resize(q);b.resize(q);
for(ll i=0;i<q;i++){
ll X=rp[i];
ll Y=lp[i];
a[i]=st[0][X];
b[i]=et[0][X];
A[i]=st[1][Y];
B[i]=et[1][Y];
}
vector<int> ans=findAns(a,b,A,B);
for(ll i=0;i<q;i++){
if(S[i]<L[i] || E[i]>R[i])ans[i]=0;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
81272 KB |
Output is correct |
2 |
Correct |
94 ms |
81144 KB |
Output is correct |
3 |
Correct |
96 ms |
81272 KB |
Output is correct |
4 |
Correct |
93 ms |
81244 KB |
Output is correct |
5 |
Correct |
81 ms |
81272 KB |
Output is correct |
6 |
Correct |
120 ms |
81272 KB |
Output is correct |
7 |
Correct |
79 ms |
81272 KB |
Output is correct |
8 |
Correct |
82 ms |
81276 KB |
Output is correct |
9 |
Correct |
77 ms |
81244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
81272 KB |
Output is correct |
2 |
Correct |
94 ms |
81144 KB |
Output is correct |
3 |
Correct |
96 ms |
81272 KB |
Output is correct |
4 |
Correct |
93 ms |
81244 KB |
Output is correct |
5 |
Correct |
81 ms |
81272 KB |
Output is correct |
6 |
Correct |
120 ms |
81272 KB |
Output is correct |
7 |
Correct |
79 ms |
81272 KB |
Output is correct |
8 |
Correct |
82 ms |
81276 KB |
Output is correct |
9 |
Correct |
77 ms |
81244 KB |
Output is correct |
10 |
Correct |
85 ms |
82044 KB |
Output is correct |
11 |
Correct |
85 ms |
82092 KB |
Output is correct |
12 |
Correct |
86 ms |
81984 KB |
Output is correct |
13 |
Correct |
86 ms |
82168 KB |
Output is correct |
14 |
Correct |
86 ms |
82296 KB |
Output is correct |
15 |
Correct |
93 ms |
82176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
856 ms |
128988 KB |
Output is correct |
2 |
Correct |
792 ms |
132840 KB |
Output is correct |
3 |
Correct |
766 ms |
129656 KB |
Output is correct |
4 |
Correct |
906 ms |
128224 KB |
Output is correct |
5 |
Correct |
801 ms |
128324 KB |
Output is correct |
6 |
Correct |
826 ms |
128812 KB |
Output is correct |
7 |
Correct |
751 ms |
126288 KB |
Output is correct |
8 |
Correct |
888 ms |
133024 KB |
Output is correct |
9 |
Correct |
773 ms |
128676 KB |
Output is correct |
10 |
Correct |
837 ms |
126836 KB |
Output is correct |
11 |
Correct |
796 ms |
127020 KB |
Output is correct |
12 |
Correct |
740 ms |
127464 KB |
Output is correct |
13 |
Correct |
973 ms |
140016 KB |
Output is correct |
14 |
Correct |
851 ms |
140012 KB |
Output is correct |
15 |
Correct |
810 ms |
140000 KB |
Output is correct |
16 |
Correct |
818 ms |
139820 KB |
Output is correct |
17 |
Correct |
737 ms |
126472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
81272 KB |
Output is correct |
2 |
Correct |
94 ms |
81144 KB |
Output is correct |
3 |
Correct |
96 ms |
81272 KB |
Output is correct |
4 |
Correct |
93 ms |
81244 KB |
Output is correct |
5 |
Correct |
81 ms |
81272 KB |
Output is correct |
6 |
Correct |
120 ms |
81272 KB |
Output is correct |
7 |
Correct |
79 ms |
81272 KB |
Output is correct |
8 |
Correct |
82 ms |
81276 KB |
Output is correct |
9 |
Correct |
77 ms |
81244 KB |
Output is correct |
10 |
Correct |
85 ms |
82044 KB |
Output is correct |
11 |
Correct |
85 ms |
82092 KB |
Output is correct |
12 |
Correct |
86 ms |
81984 KB |
Output is correct |
13 |
Correct |
86 ms |
82168 KB |
Output is correct |
14 |
Correct |
86 ms |
82296 KB |
Output is correct |
15 |
Correct |
93 ms |
82176 KB |
Output is correct |
16 |
Correct |
856 ms |
128988 KB |
Output is correct |
17 |
Correct |
792 ms |
132840 KB |
Output is correct |
18 |
Correct |
766 ms |
129656 KB |
Output is correct |
19 |
Correct |
906 ms |
128224 KB |
Output is correct |
20 |
Correct |
801 ms |
128324 KB |
Output is correct |
21 |
Correct |
826 ms |
128812 KB |
Output is correct |
22 |
Correct |
751 ms |
126288 KB |
Output is correct |
23 |
Correct |
888 ms |
133024 KB |
Output is correct |
24 |
Correct |
773 ms |
128676 KB |
Output is correct |
25 |
Correct |
837 ms |
126836 KB |
Output is correct |
26 |
Correct |
796 ms |
127020 KB |
Output is correct |
27 |
Correct |
740 ms |
127464 KB |
Output is correct |
28 |
Correct |
973 ms |
140016 KB |
Output is correct |
29 |
Correct |
851 ms |
140012 KB |
Output is correct |
30 |
Correct |
810 ms |
140000 KB |
Output is correct |
31 |
Correct |
818 ms |
139820 KB |
Output is correct |
32 |
Correct |
737 ms |
126472 KB |
Output is correct |
33 |
Correct |
914 ms |
130280 KB |
Output is correct |
34 |
Correct |
440 ms |
112880 KB |
Output is correct |
35 |
Correct |
940 ms |
133740 KB |
Output is correct |
36 |
Correct |
898 ms |
130408 KB |
Output is correct |
37 |
Correct |
885 ms |
132696 KB |
Output is correct |
38 |
Correct |
906 ms |
131008 KB |
Output is correct |
39 |
Correct |
876 ms |
143604 KB |
Output is correct |
40 |
Correct |
976 ms |
134540 KB |
Output is correct |
41 |
Correct |
875 ms |
130800 KB |
Output is correct |
42 |
Correct |
772 ms |
127576 KB |
Output is correct |
43 |
Correct |
979 ms |
137520 KB |
Output is correct |
44 |
Correct |
880 ms |
131436 KB |
Output is correct |
45 |
Correct |
808 ms |
143472 KB |
Output is correct |
46 |
Correct |
817 ms |
143416 KB |
Output is correct |
47 |
Correct |
817 ms |
140168 KB |
Output is correct |
48 |
Correct |
822 ms |
140112 KB |
Output is correct |
49 |
Correct |
831 ms |
140152 KB |
Output is correct |
50 |
Correct |
886 ms |
140084 KB |
Output is correct |
51 |
Correct |
847 ms |
131844 KB |
Output is correct |
52 |
Correct |
830 ms |
131920 KB |
Output is correct |