#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
#define vi vector<int>
const int mx = 6e5 + 5;
struct dsuTree{
int par[mx], tin[mx], tout[mx], ti, id; vector<int> adj[mx];
dsuTree(int n){
iota(par, par + n * 2, 0); id = n;
}
int get(int i){
return i == par[i] ? i : par[i] = get(par[i]);
}
void merge(int a, int b){
a = get(a); b = get(b); if (a == b) return;
adj[id].push_back(a); adj[id].push_back(b);
par[a] = par[b] = id++;
}
void dfs(int i){
tin[i] = ti++;
for (int x : adj[i]) dfs(x);
tout[i] = ti - 1;
}
};
struct segTree{
multiset<int> seg[mx * 2];
void upd(int i, int num){
for (i += mx; i; i /= 2) seg[i].insert(num);
}
bool qry(int l, int r, int a, int b){
bool ans = 0;
auto chk = [&](int i){
auto it = seg[i].lower_bound(a);
return it != seg[i].end() and *it <= b;
};
for (l += mx, r += mx; l <= r and !ans; r /= 2, l /= 2){
if (l % 2 == 1) ans |= chk(l++);
if (r % 2 == 0) ans |= chk(r--);
}
return ans;
}
};
vi check_validity(int n, vi X, vi Y, vi S, vi E, vi L, vi R){
int m = X.size(), q = L.size(); vi adj[n], QL[n], QR[n];
for (int i = 0; i < m; i++) adj[X[i]].push_back(Y[i]), adj[Y[i]].push_back(X[i]);
for (int i = 0; i < q; i++) QL[L[i]].push_back(i), QR[R[i]].push_back(i);
dsuTree TL(n), TR(n); vi st1(q), st2(q), ans(q);
for (int i = n - 1; ~i; i--){
for (int x : adj[i]) if (x > i) TL.merge(i, x);
for (int qry : QL[i]) st1[qry] = TL.get(S[qry]);
}
for (int i = 0; i < n; i++){
for (int x : adj[i]) if (x < i) TR.merge(i, x);
for (int qry : QR[i]) st2[qry] = TR.get(E[qry]);
}
TL.dfs(TL.id - 1); TR.dfs(TR.id - 1); segTree seg;
for (int i = 0; i < n; i++)
seg.upd(TL.tin[i], TR.tin[i]);
for (int i = 0; i < q; i++)
ans[i] = seg.qry(TL.tin[st1[i]], TL.tout[st1[i]], TR.tin[st2[i]], TR.tout[st2[i]]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
99016 KB |
Output is correct |
2 |
Correct |
59 ms |
98912 KB |
Output is correct |
3 |
Correct |
61 ms |
98932 KB |
Output is correct |
4 |
Correct |
59 ms |
98872 KB |
Output is correct |
5 |
Correct |
63 ms |
99012 KB |
Output is correct |
6 |
Correct |
61 ms |
98924 KB |
Output is correct |
7 |
Correct |
60 ms |
98924 KB |
Output is correct |
8 |
Correct |
61 ms |
99012 KB |
Output is correct |
9 |
Correct |
59 ms |
99012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
99016 KB |
Output is correct |
2 |
Correct |
59 ms |
98912 KB |
Output is correct |
3 |
Correct |
61 ms |
98932 KB |
Output is correct |
4 |
Correct |
59 ms |
98872 KB |
Output is correct |
5 |
Correct |
63 ms |
99012 KB |
Output is correct |
6 |
Correct |
61 ms |
98924 KB |
Output is correct |
7 |
Correct |
60 ms |
98924 KB |
Output is correct |
8 |
Correct |
61 ms |
99012 KB |
Output is correct |
9 |
Correct |
59 ms |
99012 KB |
Output is correct |
10 |
Correct |
76 ms |
102596 KB |
Output is correct |
11 |
Correct |
86 ms |
102608 KB |
Output is correct |
12 |
Correct |
79 ms |
102468 KB |
Output is correct |
13 |
Correct |
82 ms |
102560 KB |
Output is correct |
14 |
Correct |
79 ms |
102692 KB |
Output is correct |
15 |
Correct |
82 ms |
102596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3175 ms |
337664 KB |
Output is correct |
2 |
Correct |
2085 ms |
340352 KB |
Output is correct |
3 |
Correct |
2019 ms |
338624 KB |
Output is correct |
4 |
Correct |
2249 ms |
337892 KB |
Output is correct |
5 |
Correct |
2301 ms |
337772 KB |
Output is correct |
6 |
Correct |
2868 ms |
337716 KB |
Output is correct |
7 |
Correct |
3121 ms |
335312 KB |
Output is correct |
8 |
Correct |
1903 ms |
340316 KB |
Output is correct |
9 |
Correct |
1872 ms |
337480 KB |
Output is correct |
10 |
Correct |
2287 ms |
336640 KB |
Output is correct |
11 |
Correct |
2376 ms |
336716 KB |
Output is correct |
12 |
Correct |
2658 ms |
337332 KB |
Output is correct |
13 |
Correct |
2114 ms |
340252 KB |
Output is correct |
14 |
Correct |
2118 ms |
340168 KB |
Output is correct |
15 |
Correct |
2005 ms |
340152 KB |
Output is correct |
16 |
Correct |
2143 ms |
340308 KB |
Output is correct |
17 |
Correct |
3049 ms |
335428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
99016 KB |
Output is correct |
2 |
Correct |
59 ms |
98912 KB |
Output is correct |
3 |
Correct |
61 ms |
98932 KB |
Output is correct |
4 |
Correct |
59 ms |
98872 KB |
Output is correct |
5 |
Correct |
63 ms |
99012 KB |
Output is correct |
6 |
Correct |
61 ms |
98924 KB |
Output is correct |
7 |
Correct |
60 ms |
98924 KB |
Output is correct |
8 |
Correct |
61 ms |
99012 KB |
Output is correct |
9 |
Correct |
59 ms |
99012 KB |
Output is correct |
10 |
Correct |
76 ms |
102596 KB |
Output is correct |
11 |
Correct |
86 ms |
102608 KB |
Output is correct |
12 |
Correct |
79 ms |
102468 KB |
Output is correct |
13 |
Correct |
82 ms |
102560 KB |
Output is correct |
14 |
Correct |
79 ms |
102692 KB |
Output is correct |
15 |
Correct |
82 ms |
102596 KB |
Output is correct |
16 |
Correct |
3175 ms |
337664 KB |
Output is correct |
17 |
Correct |
2085 ms |
340352 KB |
Output is correct |
18 |
Correct |
2019 ms |
338624 KB |
Output is correct |
19 |
Correct |
2249 ms |
337892 KB |
Output is correct |
20 |
Correct |
2301 ms |
337772 KB |
Output is correct |
21 |
Correct |
2868 ms |
337716 KB |
Output is correct |
22 |
Correct |
3121 ms |
335312 KB |
Output is correct |
23 |
Correct |
1903 ms |
340316 KB |
Output is correct |
24 |
Correct |
1872 ms |
337480 KB |
Output is correct |
25 |
Correct |
2287 ms |
336640 KB |
Output is correct |
26 |
Correct |
2376 ms |
336716 KB |
Output is correct |
27 |
Correct |
2658 ms |
337332 KB |
Output is correct |
28 |
Correct |
2114 ms |
340252 KB |
Output is correct |
29 |
Correct |
2118 ms |
340168 KB |
Output is correct |
30 |
Correct |
2005 ms |
340152 KB |
Output is correct |
31 |
Correct |
2143 ms |
340308 KB |
Output is correct |
32 |
Correct |
3049 ms |
335428 KB |
Output is correct |
33 |
Correct |
3818 ms |
338656 KB |
Output is correct |
34 |
Correct |
333 ms |
135112 KB |
Output is correct |
35 |
Correct |
3658 ms |
349148 KB |
Output is correct |
36 |
Correct |
3796 ms |
346644 KB |
Output is correct |
37 |
Correct |
3836 ms |
348588 KB |
Output is correct |
38 |
Correct |
3878 ms |
347052 KB |
Output is correct |
39 |
Correct |
3451 ms |
351608 KB |
Output is correct |
40 |
Correct |
2900 ms |
352436 KB |
Output is correct |
41 |
Correct |
3660 ms |
348016 KB |
Output is correct |
42 |
Correct |
3242 ms |
345360 KB |
Output is correct |
43 |
Correct |
2988 ms |
352160 KB |
Output is correct |
44 |
Correct |
3663 ms |
348584 KB |
Output is correct |
45 |
Correct |
3315 ms |
350752 KB |
Output is correct |
46 |
Correct |
3330 ms |
350536 KB |
Output is correct |
47 |
Correct |
2017 ms |
348816 KB |
Output is correct |
48 |
Correct |
2050 ms |
348680 KB |
Output is correct |
49 |
Correct |
2056 ms |
348840 KB |
Output is correct |
50 |
Correct |
2087 ms |
348832 KB |
Output is correct |
51 |
Correct |
2970 ms |
351260 KB |
Output is correct |
52 |
Correct |
2913 ms |
351176 KB |
Output is correct |