#include "werewolf.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
const int mxn = 2e5 + 2;
struct reachability_tree {
int parent[mxn];
int sz[mxn];
int in[mxn],out[mxn],id[mxn];
int pc[mxn];
vector<int> g[mxn];
vector<int> w[mxn];
int T=0;
void init(int n) {
for(int i=0;i<=n;i++) {
parent[i] = i;
sz[i] = 1;
}
}
int findrep(int u) {
return parent[u] == u ? u : findrep(parent[u]);
}
void unite(int u,int v,int cst) {
u=findrep(u);
v=findrep(v);
if(u == v) return;
if(sz[u] > sz[v]) swap(u,v);
parent[u] = v;
sz[v] += sz[u];
g[v].push_back(u);
w[v].push_back(cst);
pc[u] = cst;
}
void dfs(int u) {
in[u] = ++T;
id[T] = u;
for(int v : g[u]) {
dfs(v);
}
out[u] = T;
}
pii range(int u, int tm,bool f) {
if(f)
while(parent[u] != u && pc[u] >= tm) u = parent[u];
else
while(parent[u] != u && pc[u] <= tm) u = parent[u];
int p;
if(f) {
p = upper_bound(w[u].begin(),w[u].end(),tm,[](int a,int b) {
return a > b;
}) - w[u].begin();
} else {
p = upper_bound(w[u].begin(),w[u].end(),tm) - w[u].begin();
}
if(p == 0) {
return {in[u], in[u]};
}
int v = g[u][p-1];
return {in[u],out[v]};
}
} hum,wlf ;
int U[2*mxn],V[2*mxn];
struct BIT
{
int bit[mxn];
void init() {
memset(bit,0,sizeof bit);
}
void update(int p,int v) {
if(p==0) return;
for(;p<mxn;p+=p&-p) bit[p] += v;
}
int query(int p) {
int r=0;
for(;p>0;p-=p&-p) r+=bit[p];
return r;
}
} bt;
struct Query {
int L1,R1,L2,R2;
int v;
int ind;
Query(int a,int b,int c,int d,int i) : L1(a),R1(b),L2(c),R2(d),ind(i) {};
};
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++) {
U[i] = min(X[i],Y[i]), V[i] = max(X[i],Y[i]);
}
vector<int> p1,p2;
for(int i = 0; i < m; i++) {
p1.push_back(i);
p2.push_back(i);
}
sort(p1.begin(),p1.end(),[](int a,int b) {
return U[a] > U[b];
});
sort(p2.begin(),p2.end(),[](int a,int b) {
return V[a] < V[b];
});
hum.init(N);
wlf.init(N);
int q = S.size();
vector<int> res(q);
for(int i : p1) {
hum.unite(U[i],V[i],U[i]);
}
for(int i : p2) {
wlf.unite(U[i],V[i],V[i]);
}
for(int i = 0; i < N;i++) {
if(hum.parent[i] == i) hum.dfs(i);
if(wlf.parent[i] == i) wlf.dfs(i);
}
vector<Query> Q;
vector<int> sp[mxn];
vector<int> ep[mxn];
for(int i = 0; i < q; i++) {
pii x = hum.range(S[i],L[i],true);
pii y = wlf.range(E[i],R[i],false);
Q.push_back(Query(x.f,x.s,y.f,y.s,i));
sp[x.f].push_back(i);
ep[x.s].push_back(i);
}
bt.init();
for(int i = 1 ; i <= N; i++ ) {
for(int j : sp[i]) {
Q[j].v = bt.query(Q[j].R2) - bt.query(Q[j].L2 - 1);
}
bt.update(wlf.in[hum.id[i]],1);
for(int j : ep[i]) {
int t = bt.query(Q[j].R2) - bt.query(Q[j].L2 - 1);
if(t > Q[j].v)
res[j] = 1;
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
29440 KB |
Output is correct |
2 |
Correct |
20 ms |
29312 KB |
Output is correct |
3 |
Correct |
20 ms |
29312 KB |
Output is correct |
4 |
Correct |
21 ms |
29440 KB |
Output is correct |
5 |
Correct |
21 ms |
29568 KB |
Output is correct |
6 |
Correct |
21 ms |
29440 KB |
Output is correct |
7 |
Correct |
21 ms |
29440 KB |
Output is correct |
8 |
Correct |
21 ms |
29312 KB |
Output is correct |
9 |
Correct |
21 ms |
29432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
29440 KB |
Output is correct |
2 |
Correct |
20 ms |
29312 KB |
Output is correct |
3 |
Correct |
20 ms |
29312 KB |
Output is correct |
4 |
Correct |
21 ms |
29440 KB |
Output is correct |
5 |
Correct |
21 ms |
29568 KB |
Output is correct |
6 |
Correct |
21 ms |
29440 KB |
Output is correct |
7 |
Correct |
21 ms |
29440 KB |
Output is correct |
8 |
Correct |
21 ms |
29312 KB |
Output is correct |
9 |
Correct |
21 ms |
29432 KB |
Output is correct |
10 |
Correct |
27 ms |
30132 KB |
Output is correct |
11 |
Correct |
27 ms |
30140 KB |
Output is correct |
12 |
Correct |
27 ms |
30152 KB |
Output is correct |
13 |
Correct |
28 ms |
30080 KB |
Output is correct |
14 |
Correct |
27 ms |
30072 KB |
Output is correct |
15 |
Correct |
28 ms |
30200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
778 ms |
77988 KB |
Output is correct |
2 |
Correct |
535 ms |
75472 KB |
Output is correct |
3 |
Correct |
517 ms |
75344 KB |
Output is correct |
4 |
Correct |
562 ms |
76496 KB |
Output is correct |
5 |
Correct |
595 ms |
76356 KB |
Output is correct |
6 |
Correct |
696 ms |
77392 KB |
Output is correct |
7 |
Correct |
661 ms |
76648 KB |
Output is correct |
8 |
Correct |
517 ms |
75604 KB |
Output is correct |
9 |
Correct |
455 ms |
76120 KB |
Output is correct |
10 |
Correct |
472 ms |
75608 KB |
Output is correct |
11 |
Correct |
488 ms |
75732 KB |
Output is correct |
12 |
Correct |
516 ms |
75748 KB |
Output is correct |
13 |
Correct |
561 ms |
72248 KB |
Output is correct |
14 |
Correct |
566 ms |
72328 KB |
Output is correct |
15 |
Correct |
561 ms |
72376 KB |
Output is correct |
16 |
Correct |
595 ms |
72540 KB |
Output is correct |
17 |
Correct |
678 ms |
76624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
29440 KB |
Output is correct |
2 |
Correct |
20 ms |
29312 KB |
Output is correct |
3 |
Correct |
20 ms |
29312 KB |
Output is correct |
4 |
Correct |
21 ms |
29440 KB |
Output is correct |
5 |
Correct |
21 ms |
29568 KB |
Output is correct |
6 |
Correct |
21 ms |
29440 KB |
Output is correct |
7 |
Correct |
21 ms |
29440 KB |
Output is correct |
8 |
Correct |
21 ms |
29312 KB |
Output is correct |
9 |
Correct |
21 ms |
29432 KB |
Output is correct |
10 |
Correct |
27 ms |
30132 KB |
Output is correct |
11 |
Correct |
27 ms |
30140 KB |
Output is correct |
12 |
Correct |
27 ms |
30152 KB |
Output is correct |
13 |
Correct |
28 ms |
30080 KB |
Output is correct |
14 |
Correct |
27 ms |
30072 KB |
Output is correct |
15 |
Correct |
28 ms |
30200 KB |
Output is correct |
16 |
Correct |
778 ms |
77988 KB |
Output is correct |
17 |
Correct |
535 ms |
75472 KB |
Output is correct |
18 |
Correct |
517 ms |
75344 KB |
Output is correct |
19 |
Correct |
562 ms |
76496 KB |
Output is correct |
20 |
Correct |
595 ms |
76356 KB |
Output is correct |
21 |
Correct |
696 ms |
77392 KB |
Output is correct |
22 |
Correct |
661 ms |
76648 KB |
Output is correct |
23 |
Correct |
517 ms |
75604 KB |
Output is correct |
24 |
Correct |
455 ms |
76120 KB |
Output is correct |
25 |
Correct |
472 ms |
75608 KB |
Output is correct |
26 |
Correct |
488 ms |
75732 KB |
Output is correct |
27 |
Correct |
516 ms |
75748 KB |
Output is correct |
28 |
Correct |
561 ms |
72248 KB |
Output is correct |
29 |
Correct |
566 ms |
72328 KB |
Output is correct |
30 |
Correct |
561 ms |
72376 KB |
Output is correct |
31 |
Correct |
595 ms |
72540 KB |
Output is correct |
32 |
Correct |
678 ms |
76624 KB |
Output is correct |
33 |
Correct |
723 ms |
77924 KB |
Output is correct |
34 |
Correct |
467 ms |
67544 KB |
Output is correct |
35 |
Correct |
728 ms |
77908 KB |
Output is correct |
36 |
Correct |
784 ms |
78036 KB |
Output is correct |
37 |
Correct |
766 ms |
77784 KB |
Output is correct |
38 |
Correct |
750 ms |
78296 KB |
Output is correct |
39 |
Correct |
729 ms |
76576 KB |
Output is correct |
40 |
Correct |
690 ms |
83920 KB |
Output is correct |
41 |
Correct |
595 ms |
75868 KB |
Output is correct |
42 |
Correct |
586 ms |
75736 KB |
Output is correct |
43 |
Correct |
744 ms |
79980 KB |
Output is correct |
44 |
Correct |
669 ms |
76268 KB |
Output is correct |
45 |
Correct |
574 ms |
74204 KB |
Output is correct |
46 |
Correct |
596 ms |
73652 KB |
Output is correct |
47 |
Correct |
621 ms |
72552 KB |
Output is correct |
48 |
Correct |
602 ms |
72284 KB |
Output is correct |
49 |
Correct |
626 ms |
72672 KB |
Output is correct |
50 |
Correct |
595 ms |
72140 KB |
Output is correct |
51 |
Correct |
725 ms |
83144 KB |
Output is correct |
52 |
Correct |
693 ms |
83148 KB |
Output is correct |