#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX=5e5;
class RootedTree {
public:
RootedTree() {
RE(i,MX) p[i] = -1;
}
void addChild(int parent, int child) {
chl[parent].pb(child);
p[child] = parent;
}
void createA(int u) {
a[m] = u;
bg[u] = m++;
for(int v:chl[u]) createA(v);
ed[u] = m-1;
}
void createA() {
createA(root);
}
vi chl[MX];
int p[MX];
int root;
int a[MX], bg[MX], ed[MX];
int m=0;
};
int m, q, n;
vi adj[MX];
vi atL[MX], atR[MX];
vi A, X, Y, S, E, L, R;
int p[MX], r[MX];
RootedTree treeH, treeW;
int SEG[MX*4];
int SA[MX];
int getSet(int i) {return i==p[i]?i:p[i]=getSet(p[i]);}
bool isSameSet(int i, int j) {return getSet(i)==getSet(j);}
void unionSet(int i, int j) {
if(!isSameSet(i,j)) {
i=getSet(i), j=getSet(j);
p[j] = i;
}
}
void setSeg(int i, int x, int p=0, int l=0, int r=n-1) {
if(i < l || i > r) return;
if(l == r) {
SEG[p] = x;
return;
}
int m=(l+r)/2;
setSeg(i,x,p*2+1,l,m);
setSeg(i,x,p*2+2,m+1,r);
SEG[p] = max(SEG[p*2+1], SEG[p*2+2]);
}
int getSeg(int i, int j, int p=0, int l=0, int r=n-1) {
if(j < l || i > r) return -1;
if(i <= l && j >= r) return SEG[p];
int m=(l+r)/2;
int a=getSeg(i,j,p*2+1,l,m);
int b=getSeg(i,j,p*2+2,m+1,r);
return max(a,b);
}
vi check_validity(int N, vi _X, vi _Y, vi _S, vi _E, vi _L, vi _R) {
n = N;
m = _X.size();
q = _S.size();
L=_L, R=_R, X=_X, Y=_Y, S=_S, E=_E;
A.assign(q, 0);
RE(i,m) {
adj[X[i]].pb(Y[i]);
adj[Y[i]].pb(X[i]);
}
RE(i,q) {
atL[L[i]].pb(i);
atR[R[i]].pb(i);
}
RE(i,n) p[i]=i, r[i]=0;
RE(i,n) {
for(int j:adj[i]) {
if(j > i || isSameSet(i,j)) continue;
j = getSet(j);
unionSet(i,j);
treeW.addChild(i,j);
}
for(int j:atR[i]) E[j] = getSet(E[j]);
}
treeW.root = n-1;
RE(i,n) p[i]=i, r[i]=0;
REV(i,0,n) {
for(int j:adj[i]) {
if(j < i ||isSameSet(i,j)) continue;
j = getSet(j);
unionSet(i,j);
treeH.addChild(i,j);
}
for(int j:atL[i]) S[j] = getSet(S[j]);
}
treeH.root = 0;
treeW.createA();
treeH.createA();
viii queries;
RE(curQ,q) {
int bg, ed;
int u = S[curQ];
bg = treeH.bg[u];
ed = treeH.ed[u];
queries.pb(tie(ed,bg,curQ));
}
sort(queries.begin(), queries.end());
RE(i,n*4) SEG[i] = -1;
RE(i,n) SA[treeW.a[i]] = i;
int j=0;
for(iii p : queries) {
int bg, ed, curQ;
tie(ed, bg, curQ) = p;
while(j <= ed) {
setSeg(SA[treeH.a[j]],j);
j++;
}
int u = E[curQ];
if(getSeg(treeW.bg[u], treeW.ed[u]) >= bg) {
A[curQ] = 1;
} else {
A[curQ] = 0;
}
}
return A;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
63104 KB |
Output is correct |
2 |
Correct |
43 ms |
63104 KB |
Output is correct |
3 |
Correct |
40 ms |
63096 KB |
Output is correct |
4 |
Correct |
68 ms |
62976 KB |
Output is correct |
5 |
Correct |
41 ms |
62976 KB |
Output is correct |
6 |
Correct |
47 ms |
62968 KB |
Output is correct |
7 |
Correct |
40 ms |
62972 KB |
Output is correct |
8 |
Correct |
40 ms |
63104 KB |
Output is correct |
9 |
Correct |
41 ms |
62976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
63104 KB |
Output is correct |
2 |
Correct |
43 ms |
63104 KB |
Output is correct |
3 |
Correct |
40 ms |
63096 KB |
Output is correct |
4 |
Correct |
68 ms |
62976 KB |
Output is correct |
5 |
Correct |
41 ms |
62976 KB |
Output is correct |
6 |
Correct |
47 ms |
62968 KB |
Output is correct |
7 |
Correct |
40 ms |
62972 KB |
Output is correct |
8 |
Correct |
40 ms |
63104 KB |
Output is correct |
9 |
Correct |
41 ms |
62976 KB |
Output is correct |
10 |
Correct |
52 ms |
63992 KB |
Output is correct |
11 |
Correct |
48 ms |
63864 KB |
Output is correct |
12 |
Correct |
47 ms |
63864 KB |
Output is correct |
13 |
Correct |
48 ms |
63992 KB |
Output is correct |
14 |
Correct |
55 ms |
63992 KB |
Output is correct |
15 |
Correct |
47 ms |
63996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
717 ms |
120680 KB |
Output is correct |
2 |
Correct |
695 ms |
122500 KB |
Output is correct |
3 |
Correct |
672 ms |
121220 KB |
Output is correct |
4 |
Correct |
690 ms |
120676 KB |
Output is correct |
5 |
Correct |
725 ms |
120692 KB |
Output is correct |
6 |
Correct |
761 ms |
120704 KB |
Output is correct |
7 |
Correct |
626 ms |
118376 KB |
Output is correct |
8 |
Correct |
660 ms |
122728 KB |
Output is correct |
9 |
Correct |
613 ms |
120160 KB |
Output is correct |
10 |
Correct |
576 ms |
119324 KB |
Output is correct |
11 |
Correct |
595 ms |
119652 KB |
Output is correct |
12 |
Correct |
635 ms |
120548 KB |
Output is correct |
13 |
Correct |
665 ms |
127316 KB |
Output is correct |
14 |
Correct |
656 ms |
127460 KB |
Output is correct |
15 |
Correct |
665 ms |
127276 KB |
Output is correct |
16 |
Correct |
645 ms |
127332 KB |
Output is correct |
17 |
Correct |
626 ms |
118236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
63104 KB |
Output is correct |
2 |
Correct |
43 ms |
63104 KB |
Output is correct |
3 |
Correct |
40 ms |
63096 KB |
Output is correct |
4 |
Correct |
68 ms |
62976 KB |
Output is correct |
5 |
Correct |
41 ms |
62976 KB |
Output is correct |
6 |
Correct |
47 ms |
62968 KB |
Output is correct |
7 |
Correct |
40 ms |
62972 KB |
Output is correct |
8 |
Correct |
40 ms |
63104 KB |
Output is correct |
9 |
Correct |
41 ms |
62976 KB |
Output is correct |
10 |
Correct |
52 ms |
63992 KB |
Output is correct |
11 |
Correct |
48 ms |
63864 KB |
Output is correct |
12 |
Correct |
47 ms |
63864 KB |
Output is correct |
13 |
Correct |
48 ms |
63992 KB |
Output is correct |
14 |
Correct |
55 ms |
63992 KB |
Output is correct |
15 |
Correct |
47 ms |
63996 KB |
Output is correct |
16 |
Correct |
717 ms |
120680 KB |
Output is correct |
17 |
Correct |
695 ms |
122500 KB |
Output is correct |
18 |
Correct |
672 ms |
121220 KB |
Output is correct |
19 |
Correct |
690 ms |
120676 KB |
Output is correct |
20 |
Correct |
725 ms |
120692 KB |
Output is correct |
21 |
Correct |
761 ms |
120704 KB |
Output is correct |
22 |
Correct |
626 ms |
118376 KB |
Output is correct |
23 |
Correct |
660 ms |
122728 KB |
Output is correct |
24 |
Correct |
613 ms |
120160 KB |
Output is correct |
25 |
Correct |
576 ms |
119324 KB |
Output is correct |
26 |
Correct |
595 ms |
119652 KB |
Output is correct |
27 |
Correct |
635 ms |
120548 KB |
Output is correct |
28 |
Correct |
665 ms |
127316 KB |
Output is correct |
29 |
Correct |
656 ms |
127460 KB |
Output is correct |
30 |
Correct |
665 ms |
127276 KB |
Output is correct |
31 |
Correct |
645 ms |
127332 KB |
Output is correct |
32 |
Correct |
626 ms |
118236 KB |
Output is correct |
33 |
Correct |
703 ms |
120804 KB |
Output is correct |
34 |
Correct |
429 ms |
105600 KB |
Output is correct |
35 |
Correct |
726 ms |
122808 KB |
Output is correct |
36 |
Correct |
682 ms |
121064 KB |
Output is correct |
37 |
Correct |
706 ms |
121964 KB |
Output is correct |
38 |
Correct |
701 ms |
121516 KB |
Output is correct |
39 |
Correct |
674 ms |
127224 KB |
Output is correct |
40 |
Correct |
805 ms |
129800 KB |
Output is correct |
41 |
Correct |
680 ms |
121576 KB |
Output is correct |
42 |
Correct |
629 ms |
119908 KB |
Output is correct |
43 |
Correct |
812 ms |
127976 KB |
Output is correct |
44 |
Correct |
703 ms |
121900 KB |
Output is correct |
45 |
Correct |
631 ms |
126440 KB |
Output is correct |
46 |
Correct |
638 ms |
126184 KB |
Output is correct |
47 |
Correct |
665 ms |
127660 KB |
Output is correct |
48 |
Correct |
657 ms |
127464 KB |
Output is correct |
49 |
Correct |
665 ms |
127592 KB |
Output is correct |
50 |
Correct |
655 ms |
127332 KB |
Output is correct |
51 |
Correct |
748 ms |
127588 KB |
Output is correct |
52 |
Correct |
753 ms |
127588 KB |
Output is correct |