#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; 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
99012 KB |
Output is correct |
2 |
Correct |
55 ms |
99012 KB |
Output is correct |
3 |
Correct |
59 ms |
98924 KB |
Output is correct |
4 |
Correct |
56 ms |
98848 KB |
Output is correct |
5 |
Correct |
56 ms |
99016 KB |
Output is correct |
6 |
Correct |
56 ms |
99016 KB |
Output is correct |
7 |
Correct |
53 ms |
98920 KB |
Output is correct |
8 |
Correct |
53 ms |
99016 KB |
Output is correct |
9 |
Correct |
54 ms |
99016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
99012 KB |
Output is correct |
2 |
Correct |
55 ms |
99012 KB |
Output is correct |
3 |
Correct |
59 ms |
98924 KB |
Output is correct |
4 |
Correct |
56 ms |
98848 KB |
Output is correct |
5 |
Correct |
56 ms |
99016 KB |
Output is correct |
6 |
Correct |
56 ms |
99016 KB |
Output is correct |
7 |
Correct |
53 ms |
98920 KB |
Output is correct |
8 |
Correct |
53 ms |
99016 KB |
Output is correct |
9 |
Correct |
54 ms |
99016 KB |
Output is correct |
10 |
Correct |
77 ms |
102632 KB |
Output is correct |
11 |
Correct |
76 ms |
102520 KB |
Output is correct |
12 |
Correct |
71 ms |
102516 KB |
Output is correct |
13 |
Correct |
72 ms |
102600 KB |
Output is correct |
14 |
Correct |
72 ms |
102660 KB |
Output is correct |
15 |
Correct |
72 ms |
102584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3130 ms |
337664 KB |
Output is correct |
2 |
Correct |
2877 ms |
340292 KB |
Output is correct |
3 |
Correct |
2718 ms |
338684 KB |
Output is correct |
4 |
Correct |
2388 ms |
337780 KB |
Output is correct |
5 |
Correct |
2662 ms |
337700 KB |
Output is correct |
6 |
Correct |
2896 ms |
337768 KB |
Output is correct |
7 |
Correct |
3008 ms |
335376 KB |
Output is correct |
8 |
Correct |
3047 ms |
340360 KB |
Output is correct |
9 |
Correct |
2197 ms |
337644 KB |
Output is correct |
10 |
Correct |
2385 ms |
336580 KB |
Output is correct |
11 |
Correct |
2365 ms |
336720 KB |
Output is correct |
12 |
Correct |
2632 ms |
337400 KB |
Output is correct |
13 |
Correct |
2429 ms |
340316 KB |
Output is correct |
14 |
Correct |
2462 ms |
340328 KB |
Output is correct |
15 |
Correct |
2509 ms |
340324 KB |
Output is correct |
16 |
Correct |
2378 ms |
340420 KB |
Output is correct |
17 |
Correct |
3007 ms |
335424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
99012 KB |
Output is correct |
2 |
Correct |
55 ms |
99012 KB |
Output is correct |
3 |
Correct |
59 ms |
98924 KB |
Output is correct |
4 |
Correct |
56 ms |
98848 KB |
Output is correct |
5 |
Correct |
56 ms |
99016 KB |
Output is correct |
6 |
Correct |
56 ms |
99016 KB |
Output is correct |
7 |
Correct |
53 ms |
98920 KB |
Output is correct |
8 |
Correct |
53 ms |
99016 KB |
Output is correct |
9 |
Correct |
54 ms |
99016 KB |
Output is correct |
10 |
Correct |
77 ms |
102632 KB |
Output is correct |
11 |
Correct |
76 ms |
102520 KB |
Output is correct |
12 |
Correct |
71 ms |
102516 KB |
Output is correct |
13 |
Correct |
72 ms |
102600 KB |
Output is correct |
14 |
Correct |
72 ms |
102660 KB |
Output is correct |
15 |
Correct |
72 ms |
102584 KB |
Output is correct |
16 |
Correct |
3130 ms |
337664 KB |
Output is correct |
17 |
Correct |
2877 ms |
340292 KB |
Output is correct |
18 |
Correct |
2718 ms |
338684 KB |
Output is correct |
19 |
Correct |
2388 ms |
337780 KB |
Output is correct |
20 |
Correct |
2662 ms |
337700 KB |
Output is correct |
21 |
Correct |
2896 ms |
337768 KB |
Output is correct |
22 |
Correct |
3008 ms |
335376 KB |
Output is correct |
23 |
Correct |
3047 ms |
340360 KB |
Output is correct |
24 |
Correct |
2197 ms |
337644 KB |
Output is correct |
25 |
Correct |
2385 ms |
336580 KB |
Output is correct |
26 |
Correct |
2365 ms |
336720 KB |
Output is correct |
27 |
Correct |
2632 ms |
337400 KB |
Output is correct |
28 |
Correct |
2429 ms |
340316 KB |
Output is correct |
29 |
Correct |
2462 ms |
340328 KB |
Output is correct |
30 |
Correct |
2509 ms |
340324 KB |
Output is correct |
31 |
Correct |
2378 ms |
340420 KB |
Output is correct |
32 |
Correct |
3007 ms |
335424 KB |
Output is correct |
33 |
Execution timed out |
4091 ms |
347180 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |