#include "werewolf.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
int N, M, Q;
vim V[200010];
struct sler {
int s, l, n, nd;
}sl[200010], er[200010];
struct tree {
int tp, tp1;
vim ch[400010];
int s[400010], e[400010];
void in(int a, int b) {
ch[tp].push_back(a); ch[tp].push_back(b); tp++;
}
void dfs(int now) {
s[now]=e[now]=tp1; tp1++;
for (int i:ch[now]) {
dfs(i);
e[now]=max(e[now], e[i]);
}
}
}tr1, tr2;
struct Query {
int x1, x2, y1, y2, n, ans;
}Qu[200010];
int par[200010], im[200010], dep[200010];
void Un1(int a, int b) {
while (par[a]!=-1) a=par[a];
while (par[b]!=-1) b=par[b];
if (a==b) return ;
if (dep[a]<dep[b]) swap(a, b);
par[b]=a, dep[a]=max(dep[a], dep[b]+1);
tr1.in(im[a], im[b]);
im[a]=tr1.tp-1;
}
void f1() {
tr1.tp=N, tr1.tp1=0;
for (int i=0; i<N; i++) par[i]=-1, im[i]=i, dep[i]=0;
for (int i=N-1, t=0; i>=0; i--) {
for (int j:V[i]) {
if (j>i) Un1(i, j);
}
for (; t<Q&&sl[t].l>=i; t++) {
int l=sl[t].s; while(par[l]!=-1) l=par[l];
sl[t].nd=im[l];
}
}
tr1.dfs(tr1.tp-1);
}
void Un2(int a, int b) {
while (par[a]!=-1) a=par[a];
while (par[b]!=-1) b=par[b];
if (a==b) return ;
if (dep[a]<dep[b]) swap(a, b);
par[b]=a, dep[a]=max(dep[a], dep[b]+1);
tr2.in(im[a], im[b]);
im[a]=tr2.tp-1;
}
void f2() {
tr2.tp=N, tr2.tp1=0;
for (int i=0; i<N; i++) par[i]=-1, im[i]=i, dep[i]=0;
for (int i=0, t=0; i<N; i++) {
for (int j:V[i]) {
if (j<i) Un2(i, j);
}
for (; t<Q&&er[t].l<=i; t++) {
int l=er[t].s; while(par[l]!=-1) l=par[l];
er[t].nd=im[l];
}
}
tr2.dfs(tr2.tp-1);
}
pii ar[200010];
int seg[(1<<20)];
vim check_validity(int N_, vim X, vim Y, vim S, vim E, vim L, vim R) {
N=N_; M=X.size(); Q=S.size();
for (int i=0; i<M; i++) {
V[X[i]].push_back(Y[i]);
V[Y[i]].push_back(X[i]);
}
for (int i=0; i<Q; i++) {
sl[i]={S[i], L[i], i, 0};
er[i]={E[i], R[i], i, 0};
}
sort(sl, sl+Q, [](sler a, sler b){return a.l>b.l;});
sort(er, er+Q, [](sler a, sler b){return a.l<b.l;});
f1(); f2();
sort(sl, sl+Q, [](sler a, sler b){return a.n<b.n;});
sort(er, er+Q, [](sler a, sler b){return a.n<b.n;});
for (int i=0; i<N; i++) {
ar[i]={tr1.s[i], tr2.s[i]};
assert(tr1.s[i]==tr1.e[i]&&tr2.s[i]==tr2.e[i]);
}
sort(ar, ar+N);
for (int i=0; i<Q; i++) {
int nd1=sl[i].nd, nd2=er[i].nd;
Qu[i]={tr1.s[nd1], tr1.e[nd1], tr2.s[nd2], tr2.e[nd2], i, 0};
}
sort(Qu, Qu+Q, [](Query a, Query b){return a.x2<b.x2;});
int mx=0;
for (int i=0, j=0; i<Q; i++) {
for (; j<N && ar[j].fi<=Qu[i].x2; j++) for (int k=(1<<19)+ar[j].se; k; k/=2) seg[k]=max(seg[k], ar[j].fi);
mx=0;
for (int k=(1<<19)+Qu[i].y1, l=(1<<19)+Qu[i].y2; k<=l; k/=2, l/=2) {
if (k%2) mx=max(mx, seg[k++]);
if (l%2==0) mx=max(mx, seg[l--]);
}
if (mx>=Qu[i].x1) Qu[i].ans=1;
else Qu[i].ans=0;
}
sort(Qu, Qu+Q, [](Query a, Query b){return a.n<b.n;});
vim ans;
for (int i=0; i<Q; i++) ans.push_back(Qu[i].ans);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
31 ms |
24828 KB |
Output is correct |
11 |
Correct |
30 ms |
24824 KB |
Output is correct |
12 |
Correct |
31 ms |
24696 KB |
Output is correct |
13 |
Correct |
30 ms |
24828 KB |
Output is correct |
14 |
Correct |
31 ms |
24820 KB |
Output is correct |
15 |
Correct |
32 ms |
24824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
696 ms |
77576 KB |
Output is correct |
2 |
Correct |
659 ms |
88004 KB |
Output is correct |
3 |
Correct |
625 ms |
86692 KB |
Output is correct |
4 |
Correct |
694 ms |
86156 KB |
Output is correct |
5 |
Correct |
676 ms |
86000 KB |
Output is correct |
6 |
Correct |
687 ms |
86016 KB |
Output is correct |
7 |
Correct |
685 ms |
86128 KB |
Output is correct |
8 |
Correct |
622 ms |
88020 KB |
Output is correct |
9 |
Correct |
594 ms |
86684 KB |
Output is correct |
10 |
Correct |
609 ms |
86216 KB |
Output is correct |
11 |
Correct |
630 ms |
86120 KB |
Output is correct |
12 |
Correct |
656 ms |
86016 KB |
Output is correct |
13 |
Correct |
615 ms |
87296 KB |
Output is correct |
14 |
Correct |
603 ms |
87272 KB |
Output is correct |
15 |
Correct |
610 ms |
87280 KB |
Output is correct |
16 |
Correct |
619 ms |
87280 KB |
Output is correct |
17 |
Correct |
665 ms |
85872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
31 ms |
24828 KB |
Output is correct |
11 |
Correct |
30 ms |
24824 KB |
Output is correct |
12 |
Correct |
31 ms |
24696 KB |
Output is correct |
13 |
Correct |
30 ms |
24828 KB |
Output is correct |
14 |
Correct |
31 ms |
24820 KB |
Output is correct |
15 |
Correct |
32 ms |
24824 KB |
Output is correct |
16 |
Correct |
696 ms |
77576 KB |
Output is correct |
17 |
Correct |
659 ms |
88004 KB |
Output is correct |
18 |
Correct |
625 ms |
86692 KB |
Output is correct |
19 |
Correct |
694 ms |
86156 KB |
Output is correct |
20 |
Correct |
676 ms |
86000 KB |
Output is correct |
21 |
Correct |
687 ms |
86016 KB |
Output is correct |
22 |
Correct |
685 ms |
86128 KB |
Output is correct |
23 |
Correct |
622 ms |
88020 KB |
Output is correct |
24 |
Correct |
594 ms |
86684 KB |
Output is correct |
25 |
Correct |
609 ms |
86216 KB |
Output is correct |
26 |
Correct |
630 ms |
86120 KB |
Output is correct |
27 |
Correct |
656 ms |
86016 KB |
Output is correct |
28 |
Correct |
615 ms |
87296 KB |
Output is correct |
29 |
Correct |
603 ms |
87272 KB |
Output is correct |
30 |
Correct |
610 ms |
87280 KB |
Output is correct |
31 |
Correct |
619 ms |
87280 KB |
Output is correct |
32 |
Correct |
665 ms |
85872 KB |
Output is correct |
33 |
Correct |
687 ms |
86712 KB |
Output is correct |
34 |
Correct |
442 ms |
66616 KB |
Output is correct |
35 |
Correct |
739 ms |
88560 KB |
Output is correct |
36 |
Correct |
719 ms |
86508 KB |
Output is correct |
37 |
Correct |
697 ms |
87992 KB |
Output is correct |
38 |
Correct |
715 ms |
86896 KB |
Output is correct |
39 |
Correct |
662 ms |
90380 KB |
Output is correct |
40 |
Correct |
871 ms |
93808 KB |
Output is correct |
41 |
Correct |
747 ms |
87596 KB |
Output is correct |
42 |
Correct |
653 ms |
86512 KB |
Output is correct |
43 |
Correct |
763 ms |
91460 KB |
Output is correct |
44 |
Correct |
698 ms |
88180 KB |
Output is correct |
45 |
Correct |
641 ms |
90612 KB |
Output is correct |
46 |
Correct |
651 ms |
90360 KB |
Output is correct |
47 |
Correct |
624 ms |
87536 KB |
Output is correct |
48 |
Correct |
622 ms |
87328 KB |
Output is correct |
49 |
Correct |
630 ms |
87340 KB |
Output is correct |
50 |
Correct |
618 ms |
87380 KB |
Output is correct |
51 |
Correct |
811 ms |
94468 KB |
Output is correct |
52 |
Correct |
787 ms |
94444 KB |
Output is correct |