#include "werewolf.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
typedef long long ll;
const int N = 4e5 + 5;
struct ST{
int mx[N << 2];
void set(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx) { mx[x] = v; return; }
int m = (lx + rx) >> 1;
if(i <= m) set(i, v, lx, m, x << 1);
else set(i, v, m + 1, rx, x << 1 | 1);
mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}
int get(int l, int r, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return 0;
if(lx >= l && rx <= r) return mx[x];
int m = (lx + rx) >> 1;
return max(get(l, r, lx, m, x << 1), get(l, r, m + 1, rx, x << 1 | 1));
}
}tree;
vector<int> edges[2][N];
int c[N], lift[2][N][20];
int tin[2][N], tout[2][N], t_;
int par[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(), t;
function<int(int)> f = [&](int x){ return (par[x] == x ? x : par[x] = f(par[x])); };
auto merge = [&](int a, int b){
a = f(a), b = f(b);
if(a == b){
return;
}
if(b > a && !t) swap(a, b);
if(a > b && t) swap(a, b);
edges[t][a].push_back(b);
par[b] = a;
};
vector<ar<int, 2>> e;
for(int i=0;i<m;i++){
e.push_back({max(X[i], Y[i]), i});
} sort(e.begin(), e.end());
iota(par, par + n, 0);
t = 0;
for(auto [c, i] : e){
merge(X[i], Y[i]);
} int r1 = f(0);
e.clear();
for(int i=0;i<m;i++){
e.push_back({min(X[i], Y[i]), i});
} sort(e.rbegin(), e.rend());
iota(par, par + n, 0);
t = 1;
for(auto [c, i] : e){
merge(X[i], Y[i]);
} int r2 = f(0);
//~ for(int i=0;i<m;i++){
//~ cout<<X[i] + n<<" "<<Y[i] + n<<"\n";
//~ }
//~ for(int i=0;i<n;i++){
//~ for(auto x : edges[0][i]) cout<<i<<" "<<x<<"\n";
//~ } cout<<"\n";
//~ for(int i=0;i<n;i++){
//~ for(auto x : edges[1][i]) cout<<i<<" "<<x<<"\n";
//~ } cout<<"\n";
//~ cout<<r1<<" "<<r2<<"\n";
vector<int> V;
function<void(int)> dfs = [&](int u){
tin[t][u] = ++t_;
if(t) V.push_back(u);
for(int j=1;j<20;j++){
lift[t][u][j] = lift[t][lift[t][u][j-1]][j-1];
}
for(auto x : edges[t][u]){
lift[t][x][0] = u;
dfs(x);
}
tout[t][u] = t_;
};
t = 0; t_ = 0;
lift[t][r1][0] = r1;
dfs(r1);
t = 1; t_ = 0;
lift[t][r2][0] = r2;
dfs(r2);
assert((int)V.size() == n);
int q = S.size();
vector<int> p(q); iota(p.begin(), p.end(), 0);
for(int i=0;i<q;i++){
int v = S[i];
for(int j=19;~j;j--){
if(lift[1][v][j] >= L[i]) v = lift[1][v][j];
}
S[i] = v;
v = E[i];
for(int j=19;~j;j--){
if(lift[0][v][j] <= R[i]) v = lift[0][v][j];
}
E[i] = v;
}
sort(p.begin(), p.end(), [&](int i, int j){
return tout[1][S[i]] < tout[1][S[j]];
});
vector<int> res(q);
int j = 0;
for(auto i : p){ int x = S[i];
while(j < n && j + 1 <= tout[1][x]){
tree.set(tin[0][V[j]], tin[1][V[j]]);
j++;
}
res[i] = (tree.get(tin[0][E[i]], tout[0][E[i]]) >= tin[1][x]);
}
return res;
}
/*
6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4
6 5 2
0 3
3 2
2 1
1 5
5 4
2 5 2 5
3 1 3 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
19120 KB |
Output is correct |
2 |
Correct |
10 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19156 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19156 KB |
Output is correct |
6 |
Correct |
11 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19120 KB |
Output is correct |
8 |
Correct |
11 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
19120 KB |
Output is correct |
2 |
Correct |
10 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19156 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19156 KB |
Output is correct |
6 |
Correct |
11 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19120 KB |
Output is correct |
8 |
Correct |
11 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
10 |
Correct |
16 ms |
20180 KB |
Output is correct |
11 |
Correct |
15 ms |
20180 KB |
Output is correct |
12 |
Correct |
16 ms |
20132 KB |
Output is correct |
13 |
Correct |
16 ms |
20300 KB |
Output is correct |
14 |
Correct |
16 ms |
20296 KB |
Output is correct |
15 |
Correct |
17 ms |
20320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
544 ms |
78300 KB |
Output is correct |
2 |
Correct |
539 ms |
91324 KB |
Output is correct |
3 |
Correct |
491 ms |
88268 KB |
Output is correct |
4 |
Correct |
494 ms |
86992 KB |
Output is correct |
5 |
Correct |
522 ms |
87000 KB |
Output is correct |
6 |
Correct |
550 ms |
86872 KB |
Output is correct |
7 |
Correct |
492 ms |
86696 KB |
Output is correct |
8 |
Correct |
496 ms |
91480 KB |
Output is correct |
9 |
Correct |
437 ms |
88372 KB |
Output is correct |
10 |
Correct |
389 ms |
87000 KB |
Output is correct |
11 |
Correct |
448 ms |
87052 KB |
Output is correct |
12 |
Correct |
460 ms |
86872 KB |
Output is correct |
13 |
Correct |
545 ms |
97200 KB |
Output is correct |
14 |
Correct |
525 ms |
97224 KB |
Output is correct |
15 |
Correct |
531 ms |
97240 KB |
Output is correct |
16 |
Correct |
553 ms |
97252 KB |
Output is correct |
17 |
Correct |
502 ms |
86724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
19120 KB |
Output is correct |
2 |
Correct |
10 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19156 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19156 KB |
Output is correct |
6 |
Correct |
11 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19120 KB |
Output is correct |
8 |
Correct |
11 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
10 |
Correct |
16 ms |
20180 KB |
Output is correct |
11 |
Correct |
15 ms |
20180 KB |
Output is correct |
12 |
Correct |
16 ms |
20132 KB |
Output is correct |
13 |
Correct |
16 ms |
20300 KB |
Output is correct |
14 |
Correct |
16 ms |
20296 KB |
Output is correct |
15 |
Correct |
17 ms |
20320 KB |
Output is correct |
16 |
Correct |
544 ms |
78300 KB |
Output is correct |
17 |
Correct |
539 ms |
91324 KB |
Output is correct |
18 |
Correct |
491 ms |
88268 KB |
Output is correct |
19 |
Correct |
494 ms |
86992 KB |
Output is correct |
20 |
Correct |
522 ms |
87000 KB |
Output is correct |
21 |
Correct |
550 ms |
86872 KB |
Output is correct |
22 |
Correct |
492 ms |
86696 KB |
Output is correct |
23 |
Correct |
496 ms |
91480 KB |
Output is correct |
24 |
Correct |
437 ms |
88372 KB |
Output is correct |
25 |
Correct |
389 ms |
87000 KB |
Output is correct |
26 |
Correct |
448 ms |
87052 KB |
Output is correct |
27 |
Correct |
460 ms |
86872 KB |
Output is correct |
28 |
Correct |
545 ms |
97200 KB |
Output is correct |
29 |
Correct |
525 ms |
97224 KB |
Output is correct |
30 |
Correct |
531 ms |
97240 KB |
Output is correct |
31 |
Correct |
553 ms |
97252 KB |
Output is correct |
32 |
Correct |
502 ms |
86724 KB |
Output is correct |
33 |
Correct |
620 ms |
87240 KB |
Output is correct |
34 |
Correct |
405 ms |
48372 KB |
Output is correct |
35 |
Correct |
623 ms |
90812 KB |
Output is correct |
36 |
Correct |
567 ms |
87608 KB |
Output is correct |
37 |
Correct |
598 ms |
89704 KB |
Output is correct |
38 |
Correct |
590 ms |
88484 KB |
Output is correct |
39 |
Correct |
596 ms |
100492 KB |
Output is correct |
40 |
Correct |
708 ms |
98724 KB |
Output is correct |
41 |
Correct |
497 ms |
88996 KB |
Output is correct |
42 |
Correct |
461 ms |
87700 KB |
Output is correct |
43 |
Correct |
707 ms |
97096 KB |
Output is correct |
44 |
Correct |
564 ms |
89676 KB |
Output is correct |
45 |
Correct |
539 ms |
100936 KB |
Output is correct |
46 |
Correct |
532 ms |
100616 KB |
Output is correct |
47 |
Correct |
532 ms |
97360 KB |
Output is correct |
48 |
Correct |
532 ms |
97244 KB |
Output is correct |
49 |
Correct |
534 ms |
97384 KB |
Output is correct |
50 |
Correct |
531 ms |
97284 KB |
Output is correct |
51 |
Correct |
672 ms |
98172 KB |
Output is correct |
52 |
Correct |
685 ms |
98228 KB |
Output is correct |