#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree{
int n;
vector<vector<int>> t;
void init(int _n){
n=_n;
t.assign(4*n+1, {});
}
void build(int k, int l, int r, const vector<int> &a){
if (l==r){
t[k].push_back(a[l]);
return;
}
int mid=(l+r)>>1;
build(k<<1, l, mid, a);
build(k<<1|1, mid+1, r, a);
t[k].resize(t[k<<1].size()+t[k<<1|1].size());
merge(t[k<<1].begin(), t[k<<1].end(), t[k<<1|1].begin(), t[k<<1|1].end(), t[k].begin());
}
bool get(int k, int l, int r, int L, int R, int x, int y){
if (r<L || R<l) return 0;
if (L<=l && r<=R){
return upper_bound(t[k].begin(), t[k].end(), y)!=lower_bound(t[k].begin(), t[k].end(), x);
}
int mid=(l+r)>>1;
return get(k<<1, l, mid, L, R, x, y) || get(k<<1|1, mid+1, r, L, R, x, y);
}
} st;
const int N=2e5+10, LG=18;
struct DSU{
int n;
vector<int> lab;
vector<int> g[N];
int tin[N], tout[N], tdfs;
int up[LG][N];
void init(int _n, int root){
n=_n;
lab.assign(n+1, -1);
memset(tin, 0, sizeof tin);
memset(tout, 0, sizeof tout);
tdfs=-1;
up[0][root]=root;
}
int find_set(int u){
return lab[u]<0?u:lab[u]=find_set(lab[u]);
}
void union_sets(int u, int v){
v=find_set(v);
if (v!=u){
up[0][v]=u;
g[u].push_back(v);
lab[u]+=lab[v];
lab[v]=u;
}
}
void dfs(int u){
for (int k=1; k<LG; ++k) up[k][u]=up[k-1][up[k-1][u]];
tin[u]=++tdfs;
for (int v:g[u]) dfs(v);
tout[u]=tdfs;
}
} dsu1, dsu2;
vector<int> g[N];
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();
for (int i=0; i<M; ++i) g[X[i]].push_back(Y[i]), g[Y[i]].push_back(X[i]);
int Q=S.size();
dsu1.init(N, 0);
for (int i=N-1; i>=0; --i){
for (int j:g[i]) if (j>i) dsu1.union_sets(i, j);
}
dsu2.init(N, N-1);
for (int i=0; i<N; ++i){
for (int j:g[i]) if (j<i) dsu2.union_sets(i, j);
}
dsu1.dfs(0);
dsu2.dfs(N-1);
st.init(N);
vector<int> a(N);
for (int i=0; i<N; ++i) a[dsu2.tin[i]]=dsu1.tin[i];
st.build(1, 0, N-1, a);
vector<int> ans(Q);
for (int i=0; i<Q; ++i){
for (int j=LG-1; j>=0; --j) if (dsu1.up[j][S[i]]>=L[i]) S[i]=dsu1.up[j][S[i]];
for (int j=LG-1; j>=0; --j) if (dsu2.up[j][E[i]]<=R[i]) E[i]=dsu2.up[j][E[i]];
ans[i]=st.get(1, 0, N-1, dsu2.tin[E[i]], dsu2.tout[E[i]], dsu1.tin[S[i]], dsu1.tout[S[i]]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
45660 KB |
Output is correct |
2 |
Correct |
5 ms |
45756 KB |
Output is correct |
3 |
Correct |
5 ms |
45656 KB |
Output is correct |
4 |
Correct |
5 ms |
45660 KB |
Output is correct |
5 |
Correct |
5 ms |
45660 KB |
Output is correct |
6 |
Correct |
5 ms |
45656 KB |
Output is correct |
7 |
Correct |
6 ms |
45712 KB |
Output is correct |
8 |
Correct |
7 ms |
45660 KB |
Output is correct |
9 |
Correct |
7 ms |
45660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
45660 KB |
Output is correct |
2 |
Correct |
5 ms |
45756 KB |
Output is correct |
3 |
Correct |
5 ms |
45656 KB |
Output is correct |
4 |
Correct |
5 ms |
45660 KB |
Output is correct |
5 |
Correct |
5 ms |
45660 KB |
Output is correct |
6 |
Correct |
5 ms |
45656 KB |
Output is correct |
7 |
Correct |
6 ms |
45712 KB |
Output is correct |
8 |
Correct |
7 ms |
45660 KB |
Output is correct |
9 |
Correct |
7 ms |
45660 KB |
Output is correct |
10 |
Correct |
9 ms |
46680 KB |
Output is correct |
11 |
Correct |
10 ms |
46684 KB |
Output is correct |
12 |
Correct |
9 ms |
46620 KB |
Output is correct |
13 |
Correct |
10 ms |
46684 KB |
Output is correct |
14 |
Correct |
10 ms |
46680 KB |
Output is correct |
15 |
Correct |
12 ms |
46684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
115556 KB |
Output is correct |
2 |
Correct |
379 ms |
117332 KB |
Output is correct |
3 |
Correct |
417 ms |
124504 KB |
Output is correct |
4 |
Correct |
410 ms |
123988 KB |
Output is correct |
5 |
Correct |
425 ms |
123980 KB |
Output is correct |
6 |
Correct |
502 ms |
124240 KB |
Output is correct |
7 |
Correct |
398 ms |
123732 KB |
Output is correct |
8 |
Correct |
377 ms |
125804 KB |
Output is correct |
9 |
Correct |
354 ms |
124496 KB |
Output is correct |
10 |
Correct |
288 ms |
123988 KB |
Output is correct |
11 |
Correct |
321 ms |
123984 KB |
Output is correct |
12 |
Correct |
364 ms |
123984 KB |
Output is correct |
13 |
Correct |
460 ms |
130644 KB |
Output is correct |
14 |
Correct |
422 ms |
130520 KB |
Output is correct |
15 |
Correct |
464 ms |
130644 KB |
Output is correct |
16 |
Correct |
478 ms |
130640 KB |
Output is correct |
17 |
Correct |
399 ms |
123740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
45660 KB |
Output is correct |
2 |
Correct |
5 ms |
45756 KB |
Output is correct |
3 |
Correct |
5 ms |
45656 KB |
Output is correct |
4 |
Correct |
5 ms |
45660 KB |
Output is correct |
5 |
Correct |
5 ms |
45660 KB |
Output is correct |
6 |
Correct |
5 ms |
45656 KB |
Output is correct |
7 |
Correct |
6 ms |
45712 KB |
Output is correct |
8 |
Correct |
7 ms |
45660 KB |
Output is correct |
9 |
Correct |
7 ms |
45660 KB |
Output is correct |
10 |
Correct |
9 ms |
46680 KB |
Output is correct |
11 |
Correct |
10 ms |
46684 KB |
Output is correct |
12 |
Correct |
9 ms |
46620 KB |
Output is correct |
13 |
Correct |
10 ms |
46684 KB |
Output is correct |
14 |
Correct |
10 ms |
46680 KB |
Output is correct |
15 |
Correct |
12 ms |
46684 KB |
Output is correct |
16 |
Correct |
434 ms |
115556 KB |
Output is correct |
17 |
Correct |
379 ms |
117332 KB |
Output is correct |
18 |
Correct |
417 ms |
124504 KB |
Output is correct |
19 |
Correct |
410 ms |
123988 KB |
Output is correct |
20 |
Correct |
425 ms |
123980 KB |
Output is correct |
21 |
Correct |
502 ms |
124240 KB |
Output is correct |
22 |
Correct |
398 ms |
123732 KB |
Output is correct |
23 |
Correct |
377 ms |
125804 KB |
Output is correct |
24 |
Correct |
354 ms |
124496 KB |
Output is correct |
25 |
Correct |
288 ms |
123988 KB |
Output is correct |
26 |
Correct |
321 ms |
123984 KB |
Output is correct |
27 |
Correct |
364 ms |
123984 KB |
Output is correct |
28 |
Correct |
460 ms |
130644 KB |
Output is correct |
29 |
Correct |
422 ms |
130520 KB |
Output is correct |
30 |
Correct |
464 ms |
130644 KB |
Output is correct |
31 |
Correct |
478 ms |
130640 KB |
Output is correct |
32 |
Correct |
399 ms |
123740 KB |
Output is correct |
33 |
Correct |
526 ms |
123988 KB |
Output is correct |
34 |
Correct |
197 ms |
77180 KB |
Output is correct |
35 |
Correct |
575 ms |
126032 KB |
Output is correct |
36 |
Correct |
509 ms |
124240 KB |
Output is correct |
37 |
Correct |
532 ms |
125268 KB |
Output is correct |
38 |
Correct |
494 ms |
124724 KB |
Output is correct |
39 |
Correct |
621 ms |
130608 KB |
Output is correct |
40 |
Correct |
497 ms |
133968 KB |
Output is correct |
41 |
Correct |
427 ms |
124924 KB |
Output is correct |
42 |
Correct |
309 ms |
124496 KB |
Output is correct |
43 |
Correct |
434 ms |
130384 KB |
Output is correct |
44 |
Correct |
508 ms |
125268 KB |
Output is correct |
45 |
Correct |
436 ms |
130984 KB |
Output is correct |
46 |
Correct |
403 ms |
130388 KB |
Output is correct |
47 |
Correct |
430 ms |
130928 KB |
Output is correct |
48 |
Correct |
433 ms |
130640 KB |
Output is correct |
49 |
Correct |
437 ms |
130920 KB |
Output is correct |
50 |
Correct |
455 ms |
130640 KB |
Output is correct |
51 |
Correct |
486 ms |
134004 KB |
Output is correct |
52 |
Correct |
517 ms |
133712 KB |
Output is correct |