/* In the name of GOD */
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 200012;
vector <int> g[N], t[2][N * 2];
int p[N * 2];
int par[2][N * 2];
int q;
int n;
int m;
int sz = N;
bool vis[N * 2];
void clear () {
sz = N;
for (int i = 0; i < N * 2; i++)
p[i] = i;
}
int get_par (int v) {
return (p[v] == v ? v : p[v] = get_par (p[v]));
}
void merge (int u, int v, int i) {
u = get_par (u);
v = get_par (v);
if (u == v)
return;
sz++;
p[u] = sz;
p[v] = sz;
t[i][sz].push_back(v);
t[i][sz].push_back(u);
}
struct que {
int s, e, l, r;
int v1, v2;
} qu[N];
vector <int> ll[N], rr[N];
int st [2][N * 2], ft [2][N * 2];
int ti = 1;
void dfs (int v, int i) {
vis[v] = true;
st[i][v] = ti;
for (int u : t[i][v])
dfs (u, i);
if (v < N)
ti++;
ft[i][v] = ti;
}
const int SegN = N * 4;
vector <int> seg[SegN];
int aa[N];
void build (int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
seg[v] = {aa[tl]};
return;
}
int mid = (tl + tr) >> 1;
build (v << 1, tl, mid);
build (v << 1 | 1, mid + 1, tr);
merge(seg[v << 1].begin(), seg[v << 1].end(), seg[v << 1 | 1].begin(), seg[v << 1 | 1].end(), back_inserter(seg[v]));
}
int get (int l, int r, int s, int e, int v = 1, int tl = 0, int tr = n - 1) {
if (l > tr || tl > r)
return 0;
if (l <= tl && tr <= r) {
if (lower_bound(seg[v].begin(), seg[v].end(), s) == upper_bound (seg[v].begin(), seg[v].end(), e)) {
return 0;
}
return 1;
}
int mid = (tl + tr) >> 1;
return get (l, r, s, e, v << 1, tl, mid) | get (l, r, s, e, v << 1 | 1, mid + 1, tr);
}
std::vector<int> check_validity(int NN, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R) {
q = S.size();
n = NN;
m = X.size();
for (int i = 0; i < m; i++) {
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
for (int i = 0; i < q; i++) {
qu[i].s = S[i];
qu[i].e = E[i];
qu[i].l = L[i];
qu[i].r = R[i];
ll[L[i]].push_back(i);
rr[R[i]].push_back(i);
}
clear();
for (int i = 0; i < n; i++) {
for (int j : g[i]) {
if (j < i)
merge (i, j, 0);
}
for (int j : rr[i]) {
qu[j].v1 = get_par (qu[j].e);
}
}
clear();
for (int i = n - 1; i >= 0; i--) {
for (int j : g[i])
if (j > i)
merge (i, j, 1);
for (int j : ll[i]) {
qu[j].v2 = get_par (qu[j].s);
}
}
for (int i = 2 * N - 1; i >= N; i--) {
if (!vis[i] && !t[0][i].empty()) {
dfs (i, 0);
}
}
ti = 1;
for (int i = 0; i < 2 * N; i++)
vis[i] = false;
for (int i = 2 * N - 1; i >= N; i--) {
if (!vis[i] && !t[1][i].empty()) {
dfs (i, 1);
}
}
for (int i = 0; i < 2 * N; i++) {
ft[0][i]--;
ft[1][i]--;
}
for (int i = 0; i < n; i++)
aa[st[0][i] - 1] = st[1][i];
build ();
vector <int> wef;
for (int i = 0; i < q; i++) {
wef.push_back(get (st[0][qu[i].v1] - 1, ft[0][qu[i].v1] - 1, st[1][qu[i].v2], ft[1][qu[i].v2]));
}
return wef;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
57180 KB |
Output is correct |
2 |
Correct |
25 ms |
57176 KB |
Output is correct |
3 |
Correct |
25 ms |
57180 KB |
Output is correct |
4 |
Correct |
25 ms |
57224 KB |
Output is correct |
5 |
Correct |
26 ms |
57180 KB |
Output is correct |
6 |
Correct |
25 ms |
57180 KB |
Output is correct |
7 |
Correct |
24 ms |
57180 KB |
Output is correct |
8 |
Correct |
25 ms |
57176 KB |
Output is correct |
9 |
Correct |
25 ms |
57180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
57180 KB |
Output is correct |
2 |
Correct |
25 ms |
57176 KB |
Output is correct |
3 |
Correct |
25 ms |
57180 KB |
Output is correct |
4 |
Correct |
25 ms |
57224 KB |
Output is correct |
5 |
Correct |
26 ms |
57180 KB |
Output is correct |
6 |
Correct |
25 ms |
57180 KB |
Output is correct |
7 |
Correct |
24 ms |
57180 KB |
Output is correct |
8 |
Correct |
25 ms |
57176 KB |
Output is correct |
9 |
Correct |
25 ms |
57180 KB |
Output is correct |
10 |
Correct |
30 ms |
58200 KB |
Output is correct |
11 |
Correct |
36 ms |
58284 KB |
Output is correct |
12 |
Correct |
30 ms |
58032 KB |
Output is correct |
13 |
Correct |
30 ms |
58200 KB |
Output is correct |
14 |
Correct |
30 ms |
58204 KB |
Output is correct |
15 |
Correct |
31 ms |
58156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
128712 KB |
Output is correct |
2 |
Correct |
529 ms |
134852 KB |
Output is correct |
3 |
Correct |
549 ms |
130944 KB |
Output is correct |
4 |
Correct |
530 ms |
129132 KB |
Output is correct |
5 |
Correct |
546 ms |
128968 KB |
Output is correct |
6 |
Correct |
522 ms |
128708 KB |
Output is correct |
7 |
Correct |
419 ms |
126508 KB |
Output is correct |
8 |
Correct |
507 ms |
134852 KB |
Output is correct |
9 |
Correct |
496 ms |
129856 KB |
Output is correct |
10 |
Correct |
379 ms |
127776 KB |
Output is correct |
11 |
Correct |
375 ms |
136132 KB |
Output is correct |
12 |
Correct |
482 ms |
136908 KB |
Output is correct |
13 |
Correct |
491 ms |
143300 KB |
Output is correct |
14 |
Correct |
438 ms |
143344 KB |
Output is correct |
15 |
Correct |
478 ms |
143476 KB |
Output is correct |
16 |
Correct |
454 ms |
143436 KB |
Output is correct |
17 |
Correct |
395 ms |
134852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
57180 KB |
Output is correct |
2 |
Correct |
25 ms |
57176 KB |
Output is correct |
3 |
Correct |
25 ms |
57180 KB |
Output is correct |
4 |
Correct |
25 ms |
57224 KB |
Output is correct |
5 |
Correct |
26 ms |
57180 KB |
Output is correct |
6 |
Correct |
25 ms |
57180 KB |
Output is correct |
7 |
Correct |
24 ms |
57180 KB |
Output is correct |
8 |
Correct |
25 ms |
57176 KB |
Output is correct |
9 |
Correct |
25 ms |
57180 KB |
Output is correct |
10 |
Correct |
30 ms |
58200 KB |
Output is correct |
11 |
Correct |
36 ms |
58284 KB |
Output is correct |
12 |
Correct |
30 ms |
58032 KB |
Output is correct |
13 |
Correct |
30 ms |
58200 KB |
Output is correct |
14 |
Correct |
30 ms |
58204 KB |
Output is correct |
15 |
Correct |
31 ms |
58156 KB |
Output is correct |
16 |
Correct |
462 ms |
128712 KB |
Output is correct |
17 |
Correct |
529 ms |
134852 KB |
Output is correct |
18 |
Correct |
549 ms |
130944 KB |
Output is correct |
19 |
Correct |
530 ms |
129132 KB |
Output is correct |
20 |
Correct |
546 ms |
128968 KB |
Output is correct |
21 |
Correct |
522 ms |
128708 KB |
Output is correct |
22 |
Correct |
419 ms |
126508 KB |
Output is correct |
23 |
Correct |
507 ms |
134852 KB |
Output is correct |
24 |
Correct |
496 ms |
129856 KB |
Output is correct |
25 |
Correct |
379 ms |
127776 KB |
Output is correct |
26 |
Correct |
375 ms |
136132 KB |
Output is correct |
27 |
Correct |
482 ms |
136908 KB |
Output is correct |
28 |
Correct |
491 ms |
143300 KB |
Output is correct |
29 |
Correct |
438 ms |
143344 KB |
Output is correct |
30 |
Correct |
478 ms |
143476 KB |
Output is correct |
31 |
Correct |
454 ms |
143436 KB |
Output is correct |
32 |
Correct |
395 ms |
134852 KB |
Output is correct |
33 |
Correct |
598 ms |
138728 KB |
Output is correct |
34 |
Correct |
209 ms |
95432 KB |
Output is correct |
35 |
Correct |
774 ms |
143044 KB |
Output is correct |
36 |
Correct |
585 ms |
138176 KB |
Output is correct |
37 |
Correct |
726 ms |
142072 KB |
Output is correct |
38 |
Correct |
646 ms |
138836 KB |
Output is correct |
39 |
Correct |
607 ms |
149752 KB |
Output is correct |
40 |
Correct |
474 ms |
145396 KB |
Output is correct |
41 |
Correct |
590 ms |
141000 KB |
Output is correct |
42 |
Correct |
357 ms |
136900 KB |
Output is correct |
43 |
Correct |
728 ms |
147144 KB |
Output is correct |
44 |
Correct |
630 ms |
141992 KB |
Output is correct |
45 |
Correct |
477 ms |
148980 KB |
Output is correct |
46 |
Correct |
483 ms |
148676 KB |
Output is correct |
47 |
Correct |
445 ms |
143560 KB |
Output is correct |
48 |
Correct |
520 ms |
143304 KB |
Output is correct |
49 |
Correct |
427 ms |
143616 KB |
Output is correct |
50 |
Correct |
424 ms |
143452 KB |
Output is correct |
51 |
Correct |
443 ms |
144072 KB |
Output is correct |
52 |
Correct |
436 ms |
144072 KB |
Output is correct |