#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n;
struct Tree {
int root[N];
int par[18][N];
vector<int> g[N];
vector<pair<int, int>> edge;
int tin[N], tout[N], tt;
void add(int u,int v) {
edge.emplace_back(u, v);
}
void dfs(int u, int p) {
par[0][u] = p;
tin[u] = ++tt;
for (int i = 1; i < 18; ++i) par[i][u] = par[i - 1][par[i - 1][u]];
for (int v : g[u]) {
dfs(v, u);
}
tout[u] = tt;
}
int anc(int u) {
return root[u] == u ? u : root[u] = anc(root[u]);
}
void build() {
for (int i = 0; i < n; ++i) root[i] = i;
sort(edge.begin(), edge.end());
for (auto e : edge) {
int u = abs(e.first), v = abs(e.second);
u = anc(u), v = anc(v);
if (u ^ v) {
g[u].push_back(v);
root[v] = u;
}
}
}
int getL(int u,int l) {
for (int i = 17; i >= 0; --i) {
if (par[i][u] >= l) u = par[i][u];
}
return u;
}
int getR(int u,int r) {
for (int i = 17; i >= 0; --i) {
if (par[i][u] <= r) u = par[i][u];
}
return u;
}
} pre, suf;
int ft[N];
void add(int p) {
for (; p <= n; p += p & -p) ft[p]++;
}
int get(int p) {
int ans = 0;
for (; p > 0; p -= p & -p) ans += ft[p];
return ans;
}
int get(int l,int r) {
return get(r) - get(l - 1);
}
struct Query {
int l, r, id, sgn;
Query(int l = 0,int r = 0,int id = 0,int sgn = 0) : l(l), r(r), id(id), sgn(sgn) {}
bool operator < (const Query &q) const {
return r < q.r;
}
};
int ans[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) {
::n = n;
int m = x.size(), q = s.size();
for (int i = 0; i < m; ++i) {
if (x[i] < y[i]) swap(x[i], y[i]);
pre.add(x[i], y[i]);
suf.add(-y[i], -x[i]);
}
pre.build();
suf.build();
pre.dfs(n - 1, n - 1);
suf.dfs(0, 0);
vector<vector<int>> ps(n + 1);
for (int i = 0; i < n; ++i) {
ps[pre.tin[i]].push_back(suf.tin[i]);
}
vector<vector<Query>> qs(n + 1);
for (int i = 0; i < q; ++i) {
int u = pre.getR(e[i], r[i]), v = suf.getL(s[i], l[i]);
qs[pre.tin[u] - 1].push_back(Query(suf.tin[v], suf.tout[v], i, -1));
qs[pre.tout[u]].push_back(Query(suf.tin[v], suf.tout[v], i, 1));
}
for (int i = 0; i <= n; ++i) {
for (int p : ps[i]) {
add(p);
}
for (auto q : qs[i]) {
ans[q.id] += q.sgn * get(q.l, q.r);
}
}
for (int i = 0; i < q; ++i) ans[i] = ans[i] > 0;
return vector<int>(ans, ans + q);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9984 KB |
Output is correct |
2 |
Correct |
13 ms |
9984 KB |
Output is correct |
3 |
Correct |
14 ms |
9984 KB |
Output is correct |
4 |
Correct |
16 ms |
9984 KB |
Output is correct |
5 |
Correct |
10 ms |
9984 KB |
Output is correct |
6 |
Correct |
10 ms |
9984 KB |
Output is correct |
7 |
Correct |
10 ms |
10112 KB |
Output is correct |
8 |
Correct |
9 ms |
9984 KB |
Output is correct |
9 |
Correct |
10 ms |
9984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9984 KB |
Output is correct |
2 |
Correct |
13 ms |
9984 KB |
Output is correct |
3 |
Correct |
14 ms |
9984 KB |
Output is correct |
4 |
Correct |
16 ms |
9984 KB |
Output is correct |
5 |
Correct |
10 ms |
9984 KB |
Output is correct |
6 |
Correct |
10 ms |
9984 KB |
Output is correct |
7 |
Correct |
10 ms |
10112 KB |
Output is correct |
8 |
Correct |
9 ms |
9984 KB |
Output is correct |
9 |
Correct |
10 ms |
9984 KB |
Output is correct |
10 |
Correct |
16 ms |
11264 KB |
Output is correct |
11 |
Correct |
33 ms |
11264 KB |
Output is correct |
12 |
Correct |
17 ms |
11264 KB |
Output is correct |
13 |
Correct |
18 ms |
11392 KB |
Output is correct |
14 |
Correct |
16 ms |
11392 KB |
Output is correct |
15 |
Correct |
17 ms |
11392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1669 ms |
92036 KB |
Output is correct |
2 |
Correct |
1273 ms |
94376 KB |
Output is correct |
3 |
Correct |
1200 ms |
92736 KB |
Output is correct |
4 |
Correct |
1239 ms |
91664 KB |
Output is correct |
5 |
Correct |
1247 ms |
91712 KB |
Output is correct |
6 |
Correct |
1405 ms |
91712 KB |
Output is correct |
7 |
Correct |
1180 ms |
90448 KB |
Output is correct |
8 |
Correct |
943 ms |
94316 KB |
Output is correct |
9 |
Correct |
662 ms |
92636 KB |
Output is correct |
10 |
Correct |
509 ms |
90456 KB |
Output is correct |
11 |
Correct |
542 ms |
91356 KB |
Output is correct |
12 |
Correct |
582 ms |
91064 KB |
Output is correct |
13 |
Correct |
1104 ms |
98172 KB |
Output is correct |
14 |
Correct |
1124 ms |
98268 KB |
Output is correct |
15 |
Correct |
1196 ms |
98140 KB |
Output is correct |
16 |
Correct |
1195 ms |
98136 KB |
Output is correct |
17 |
Correct |
1285 ms |
90524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9984 KB |
Output is correct |
2 |
Correct |
13 ms |
9984 KB |
Output is correct |
3 |
Correct |
14 ms |
9984 KB |
Output is correct |
4 |
Correct |
16 ms |
9984 KB |
Output is correct |
5 |
Correct |
10 ms |
9984 KB |
Output is correct |
6 |
Correct |
10 ms |
9984 KB |
Output is correct |
7 |
Correct |
10 ms |
10112 KB |
Output is correct |
8 |
Correct |
9 ms |
9984 KB |
Output is correct |
9 |
Correct |
10 ms |
9984 KB |
Output is correct |
10 |
Correct |
16 ms |
11264 KB |
Output is correct |
11 |
Correct |
33 ms |
11264 KB |
Output is correct |
12 |
Correct |
17 ms |
11264 KB |
Output is correct |
13 |
Correct |
18 ms |
11392 KB |
Output is correct |
14 |
Correct |
16 ms |
11392 KB |
Output is correct |
15 |
Correct |
17 ms |
11392 KB |
Output is correct |
16 |
Correct |
1669 ms |
92036 KB |
Output is correct |
17 |
Correct |
1273 ms |
94376 KB |
Output is correct |
18 |
Correct |
1200 ms |
92736 KB |
Output is correct |
19 |
Correct |
1239 ms |
91664 KB |
Output is correct |
20 |
Correct |
1247 ms |
91712 KB |
Output is correct |
21 |
Correct |
1405 ms |
91712 KB |
Output is correct |
22 |
Correct |
1180 ms |
90448 KB |
Output is correct |
23 |
Correct |
943 ms |
94316 KB |
Output is correct |
24 |
Correct |
662 ms |
92636 KB |
Output is correct |
25 |
Correct |
509 ms |
90456 KB |
Output is correct |
26 |
Correct |
542 ms |
91356 KB |
Output is correct |
27 |
Correct |
582 ms |
91064 KB |
Output is correct |
28 |
Correct |
1104 ms |
98172 KB |
Output is correct |
29 |
Correct |
1124 ms |
98268 KB |
Output is correct |
30 |
Correct |
1196 ms |
98140 KB |
Output is correct |
31 |
Correct |
1195 ms |
98136 KB |
Output is correct |
32 |
Correct |
1285 ms |
90524 KB |
Output is correct |
33 |
Correct |
1528 ms |
91756 KB |
Output is correct |
34 |
Correct |
477 ms |
39804 KB |
Output is correct |
35 |
Correct |
1428 ms |
94016 KB |
Output is correct |
36 |
Correct |
1458 ms |
92296 KB |
Output is correct |
37 |
Correct |
1399 ms |
93084 KB |
Output is correct |
38 |
Correct |
1514 ms |
92700 KB |
Output is correct |
39 |
Correct |
1360 ms |
97756 KB |
Output is correct |
40 |
Correct |
995 ms |
110728 KB |
Output is correct |
41 |
Correct |
971 ms |
99312 KB |
Output is correct |
42 |
Correct |
762 ms |
98968 KB |
Output is correct |
43 |
Correct |
1267 ms |
108056 KB |
Output is correct |
44 |
Correct |
1119 ms |
101064 KB |
Output is correct |
45 |
Correct |
793 ms |
106472 KB |
Output is correct |
46 |
Correct |
891 ms |
105900 KB |
Output is correct |
47 |
Correct |
1113 ms |
106156 KB |
Output is correct |
48 |
Correct |
1138 ms |
105968 KB |
Output is correct |
49 |
Correct |
1097 ms |
106260 KB |
Output is correct |
50 |
Correct |
1095 ms |
106036 KB |
Output is correct |
51 |
Correct |
907 ms |
110024 KB |
Output is correct |
52 |
Correct |
861 ms |
109908 KB |
Output is correct |