#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define fi first
#define se second
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){for(auto x:v)outv(x);}
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
const ll inf=1001001001001001001;
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 Q = S.size();
vvi g(n);
rep(i,X.size()){
g[X[i]].pb(Y[i]);g[Y[i]].pb(X[i]);
}
vi parL(n,-1),parR(n,-1);
vvi queryL(n),queryR(n);
{
vi pp(n,-1);
function<ll(ll)> root=[&](ll i){
if(pp[i]==-1)return i;
pp[i]=root(pp[i]);
return pp[i];
};
vvi tmp(n);
rep(i,Q)tmp[L[i]].pb(i);
for(int i=n-1;i>=0;i--){
for(auto x:g[i])if(x>i){
ll t=root(x);
if(t!=i)parL[t]=pp[t]=i;
}
for(ll x:tmp[i])queryL[root(S[x])].pb(x);
}
}
{
vi pp(n,-1);
function<ll(ll)> root=[&](ll i){
if(pp[i]==-1)return i;
pp[i]=root(pp[i]);
return pp[i];
};
vvi tmp(n);
rep(i,Q)tmp[R[i]].pb(i);
rep(i,n){
for(auto x:g[i])if(x<i){
ll t=root(x);
if(t!=i)parR[t]=pp[t]=i;
}
for(ll x:tmp[i])queryR[root(E[x])].pb(x);
}
}
vvi gL(n),gR(n);
rep(i,n)if(parL[i]!=-1)gL[parL[i]].pb(i);
rep(i,n)if(parR[i]!=-1)gR[parR[i]].pb(i);
ll cnt=0;
vp euler(n);
function<void(ll)> dfs0=[&](ll i){
euler[i].fi=cnt++;
for(ll x:gR[i])dfs0(x);
euler[i].se=cnt;
};dfs0(n-1);
vp rng(Q);
rep(i,n)for(auto x:queryR[i])rng[x]=euler[i];
vector<set<ll>> dp(n);
vector<int> ans(Q);
// outv(parR);
// for(auto x:rng)cout<<x.fi<<' '<<x.se<<endl;
// for(auto x:euler)cout<<x.fi<<' '<<x.se<<endl;
function<void(ll)> dfs1=[&](ll i){
dp[i].insert(euler[i].fi);
for(ll x:gL[i]){
dfs1(x);
if(dp[i].size()<dp[x].size())swap(dp[i],dp[x]);
for(ll y:dp[x])dp[i].insert(y);
}
for(auto x:queryL[i]){
auto itr=dp[i].lower_bound(rng[x].fi);
if(itr!=dp[i].end()&&*itr<rng[x].se)ans[x]=1;
}
};dfs1(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
10 ms |
2004 KB |
Output is correct |
11 |
Correct |
10 ms |
1876 KB |
Output is correct |
12 |
Correct |
10 ms |
2140 KB |
Output is correct |
13 |
Correct |
8 ms |
2136 KB |
Output is correct |
14 |
Correct |
7 ms |
2260 KB |
Output is correct |
15 |
Correct |
8 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
978 ms |
139236 KB |
Output is correct |
2 |
Correct |
667 ms |
116076 KB |
Output is correct |
3 |
Correct |
791 ms |
123164 KB |
Output is correct |
4 |
Correct |
758 ms |
137096 KB |
Output is correct |
5 |
Correct |
933 ms |
140240 KB |
Output is correct |
6 |
Correct |
1126 ms |
146004 KB |
Output is correct |
7 |
Correct |
792 ms |
148364 KB |
Output is correct |
8 |
Correct |
643 ms |
116008 KB |
Output is correct |
9 |
Correct |
557 ms |
122652 KB |
Output is correct |
10 |
Correct |
608 ms |
136488 KB |
Output is correct |
11 |
Correct |
634 ms |
137944 KB |
Output is correct |
12 |
Correct |
721 ms |
143824 KB |
Output is correct |
13 |
Correct |
619 ms |
119812 KB |
Output is correct |
14 |
Correct |
727 ms |
119924 KB |
Output is correct |
15 |
Correct |
585 ms |
119820 KB |
Output is correct |
16 |
Correct |
593 ms |
119896 KB |
Output is correct |
17 |
Correct |
862 ms |
146432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
10 ms |
2004 KB |
Output is correct |
11 |
Correct |
10 ms |
1876 KB |
Output is correct |
12 |
Correct |
10 ms |
2140 KB |
Output is correct |
13 |
Correct |
8 ms |
2136 KB |
Output is correct |
14 |
Correct |
7 ms |
2260 KB |
Output is correct |
15 |
Correct |
8 ms |
2132 KB |
Output is correct |
16 |
Correct |
978 ms |
139236 KB |
Output is correct |
17 |
Correct |
667 ms |
116076 KB |
Output is correct |
18 |
Correct |
791 ms |
123164 KB |
Output is correct |
19 |
Correct |
758 ms |
137096 KB |
Output is correct |
20 |
Correct |
933 ms |
140240 KB |
Output is correct |
21 |
Correct |
1126 ms |
146004 KB |
Output is correct |
22 |
Correct |
792 ms |
148364 KB |
Output is correct |
23 |
Correct |
643 ms |
116008 KB |
Output is correct |
24 |
Correct |
557 ms |
122652 KB |
Output is correct |
25 |
Correct |
608 ms |
136488 KB |
Output is correct |
26 |
Correct |
634 ms |
137944 KB |
Output is correct |
27 |
Correct |
721 ms |
143824 KB |
Output is correct |
28 |
Correct |
619 ms |
119812 KB |
Output is correct |
29 |
Correct |
727 ms |
119924 KB |
Output is correct |
30 |
Correct |
585 ms |
119820 KB |
Output is correct |
31 |
Correct |
593 ms |
119896 KB |
Output is correct |
32 |
Correct |
862 ms |
146432 KB |
Output is correct |
33 |
Correct |
835 ms |
118436 KB |
Output is correct |
34 |
Correct |
259 ms |
45960 KB |
Output is correct |
35 |
Correct |
813 ms |
115924 KB |
Output is correct |
36 |
Correct |
813 ms |
121304 KB |
Output is correct |
37 |
Correct |
860 ms |
115340 KB |
Output is correct |
38 |
Correct |
822 ms |
119760 KB |
Output is correct |
39 |
Correct |
825 ms |
138688 KB |
Output is correct |
40 |
Correct |
858 ms |
126056 KB |
Output is correct |
41 |
Correct |
699 ms |
112936 KB |
Output is correct |
42 |
Correct |
714 ms |
118364 KB |
Output is correct |
43 |
Correct |
939 ms |
121792 KB |
Output is correct |
44 |
Correct |
794 ms |
113576 KB |
Output is correct |
45 |
Correct |
768 ms |
130476 KB |
Output is correct |
46 |
Correct |
876 ms |
138852 KB |
Output is correct |
47 |
Correct |
605 ms |
120228 KB |
Output is correct |
48 |
Correct |
598 ms |
119812 KB |
Output is correct |
49 |
Correct |
591 ms |
120172 KB |
Output is correct |
50 |
Correct |
625 ms |
120020 KB |
Output is correct |
51 |
Correct |
871 ms |
124020 KB |
Output is correct |
52 |
Correct |
734 ms |
123860 KB |
Output is correct |