#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAXN = (int) 5e5 + 5;
int n;
int t[MAXN];
void upd(int v, int val){
for(; v < MAXN; v += (v&-v))
t[v] += val;
}
int gt(int l, int r){
l--;
int res = 0;
for(; r; r -= (r&-r)) res += t[r];
for(; l; l -= (l&-l)) res -= t[l];
return res;
}
vector<pair<int, int>> Qs[MAXN];
vector<int> A;
struct ali{
int cev[MAXN], tin[MAXN], tout[MAXN], sz[MAXN], pari[MAXN][22];
int cur = 1;
int par[MAXN];
vector<int> adj[MAXN];
void ini(){
for(int i = 0; i < n; i++){
adj[i].clear();
sz[i] = 1;
par[i] = i;
pari[i][0] = i;
}
}
int find_set(int v){
if(par[v] == v) return v;
return par[v] = find_set(par[v]);
}
void merge(int a, int b, bool cr){
a = find_set(a);
b = find_set(b);
if(a == b) return;
if(cr){
if(a < b)
swap(a, b);
sz[a] += sz[b];
par[b] = a;
pari[b][0] = a;
adj[a].push_back(b);
}else{
if(a > b)
swap(a, b);
sz[a] += sz[b];
par[b] = a;
pari[b][0] = a;
adj[a].push_back(b);
}
}
void dfs(int v){
tin[v] = cur++;
cev[cur - 1] = v;
for(int l = 1; l < 22; l++)
pari[v][l] = pari[pari[v][l - 1]][l - 1];
for(int j: adj[v])
dfs(j);
tout[v] = cur - 1;
}
void dfs2(int v, bool keep, ali &s){
int hv = -1;
for(int j: adj[v])
if(hv == -1 || sz[j] > sz[hv])
hv = j;
for(int j: adj[v])
if(j != hv)
dfs2(j, 0, s);
if(hv != -1)
dfs2(hv, 1, s);
for(int j: adj[v])
if(j != hv)
for(int i = tin[j]; i <= tout[j]; i++)
upd(s.tin[cev[i]], 1);
upd(s.tin[v], 1);
for(auto j: Qs[v]){
int rs = gt(s.tin[j.first], s.tout[j.first]);
assert(rs >= 0);
A[j.second] = (rs != 0);
}
if(keep == 0)
for(int i = tin[v]; i <= tout[v]; i++)
upd(s.tin[cev[i]], -1);
}
} st1, st2;
vi check_validity(int N, vi X, vi Y, vi S, vi E, vi L, vi R) {
n = N;
int M = X.size(), Q = S.size();
st1.ini();
st2.ini();
A.resize(Q);
vector<int> esi;
for(int i = 0; i < M; i++){
esi.push_back(i);
}
sort(esi.begin(), esi.end(), [&X, &Y](int a, int b){
if(min(X[a], Y[a]) == min(X[b], Y[b])){
return max(X[a], Y[a]) < max(X[b], Y[b]);
}
return min(X[a], Y[a]) > min(X[b], Y[b]);
});
st1.ini(); st2.ini();
for(int i = 0; i < M; i++){
st1.merge(X[esi[i]], Y[esi[i]], 0);
}
sort(esi.begin(), esi.end(), [&X, &Y](int a, int b){
if(max(X[a], Y[a]) == max(X[b], Y[b]))
return min(X[a], Y[a]) > min(X[b], Y[b]);
return max(X[a], Y[a]) < max(X[b], Y[b]);
});
for(int i = 0; i < M; i++){
st2.merge(X[esi[i]], Y[esi[i]], 1);
}
st1.dfs(0);
st2.dfs(n - 1);
for(int i = 0; i < Q; i++){
for(int j = 21; j >= 0; j--){
if(st1.pari[S[i]][j] >= L[i]){
S[i] = st1.pari[S[i]][j];
}
}
for(int j = 21; j >= 0; j--){
if(st2.pari[E[i]][j] <= R[i]){
E[i] = st2.pari[E[i]][j];
}
}
Qs[S[i]].push_back({E[i], i});
}
st1.dfs2(0, 1, st2);
return A;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
35712 KB |
Output is correct |
2 |
Correct |
24 ms |
35704 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
24 ms |
35708 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
24 ms |
35704 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
25 ms |
35712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
35712 KB |
Output is correct |
2 |
Correct |
24 ms |
35704 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
24 ms |
35708 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
24 ms |
35704 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
25 ms |
35712 KB |
Output is correct |
10 |
Correct |
33 ms |
36856 KB |
Output is correct |
11 |
Correct |
32 ms |
36864 KB |
Output is correct |
12 |
Correct |
33 ms |
36856 KB |
Output is correct |
13 |
Correct |
33 ms |
36936 KB |
Output is correct |
14 |
Correct |
29 ms |
36900 KB |
Output is correct |
15 |
Correct |
34 ms |
36992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
994 ms |
103088 KB |
Output is correct |
2 |
Correct |
967 ms |
113420 KB |
Output is correct |
3 |
Correct |
862 ms |
110784 KB |
Output is correct |
4 |
Correct |
835 ms |
109804 KB |
Output is correct |
5 |
Correct |
846 ms |
110024 KB |
Output is correct |
6 |
Correct |
964 ms |
110464 KB |
Output is correct |
7 |
Correct |
997 ms |
109780 KB |
Output is correct |
8 |
Correct |
879 ms |
113220 KB |
Output is correct |
9 |
Correct |
760 ms |
110728 KB |
Output is correct |
10 |
Correct |
730 ms |
109576 KB |
Output is correct |
11 |
Correct |
735 ms |
109444 KB |
Output is correct |
12 |
Correct |
875 ms |
109428 KB |
Output is correct |
13 |
Correct |
1069 ms |
124424 KB |
Output is correct |
14 |
Correct |
979 ms |
124324 KB |
Output is correct |
15 |
Correct |
1010 ms |
124368 KB |
Output is correct |
16 |
Correct |
990 ms |
124424 KB |
Output is correct |
17 |
Correct |
982 ms |
109976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
35712 KB |
Output is correct |
2 |
Correct |
24 ms |
35704 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
24 ms |
35708 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
24 ms |
35704 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
25 ms |
35712 KB |
Output is correct |
10 |
Correct |
33 ms |
36856 KB |
Output is correct |
11 |
Correct |
32 ms |
36864 KB |
Output is correct |
12 |
Correct |
33 ms |
36856 KB |
Output is correct |
13 |
Correct |
33 ms |
36936 KB |
Output is correct |
14 |
Correct |
29 ms |
36900 KB |
Output is correct |
15 |
Correct |
34 ms |
36992 KB |
Output is correct |
16 |
Correct |
994 ms |
103088 KB |
Output is correct |
17 |
Correct |
967 ms |
113420 KB |
Output is correct |
18 |
Correct |
862 ms |
110784 KB |
Output is correct |
19 |
Correct |
835 ms |
109804 KB |
Output is correct |
20 |
Correct |
846 ms |
110024 KB |
Output is correct |
21 |
Correct |
964 ms |
110464 KB |
Output is correct |
22 |
Correct |
997 ms |
109780 KB |
Output is correct |
23 |
Correct |
879 ms |
113220 KB |
Output is correct |
24 |
Correct |
760 ms |
110728 KB |
Output is correct |
25 |
Correct |
730 ms |
109576 KB |
Output is correct |
26 |
Correct |
735 ms |
109444 KB |
Output is correct |
27 |
Correct |
875 ms |
109428 KB |
Output is correct |
28 |
Correct |
1069 ms |
124424 KB |
Output is correct |
29 |
Correct |
979 ms |
124324 KB |
Output is correct |
30 |
Correct |
1010 ms |
124368 KB |
Output is correct |
31 |
Correct |
990 ms |
124424 KB |
Output is correct |
32 |
Correct |
982 ms |
109976 KB |
Output is correct |
33 |
Correct |
1076 ms |
111748 KB |
Output is correct |
34 |
Correct |
756 ms |
65896 KB |
Output is correct |
35 |
Correct |
1104 ms |
116652 KB |
Output is correct |
36 |
Correct |
1049 ms |
112192 KB |
Output is correct |
37 |
Correct |
1126 ms |
115308 KB |
Output is correct |
38 |
Correct |
1064 ms |
113112 KB |
Output is correct |
39 |
Correct |
1049 ms |
121492 KB |
Output is correct |
40 |
Correct |
1253 ms |
122632 KB |
Output is correct |
41 |
Correct |
920 ms |
113324 KB |
Output is correct |
42 |
Correct |
860 ms |
110636 KB |
Output is correct |
43 |
Correct |
1184 ms |
123272 KB |
Output is correct |
44 |
Correct |
1065 ms |
114416 KB |
Output is correct |
45 |
Correct |
894 ms |
120684 KB |
Output is correct |
46 |
Correct |
899 ms |
120172 KB |
Output is correct |
47 |
Correct |
1029 ms |
124524 KB |
Output is correct |
48 |
Correct |
1030 ms |
124476 KB |
Output is correct |
49 |
Correct |
1002 ms |
124588 KB |
Output is correct |
50 |
Correct |
1052 ms |
124504 KB |
Output is correct |
51 |
Correct |
1196 ms |
121372 KB |
Output is correct |
52 |
Correct |
1250 ms |
121436 KB |
Output is correct |