#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
const int N = 200010;
pair <int, int> x_range[N], y_range[N];
vector <int> g[N], who[N], adj[N], t[N << 1];
int root[N], p[N], x_in[N], y_in[N], x_out[N], y_out[N], ptr, x_sub[N], y_sub[N];
int find (int x) {
return root[x] == x ? x : root[x] = find(root[x]);
}
void dfs (int* a, int *b, int u) {
a[u] = ptr++;
for (int v : adj[u]) dfs(a, b, v);
b[u] = ptr;
}
int query (int n, int l, int r, int lo, int hi) {
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
vector <int> &vec = t[l++];
int here = lower_bound(vec.begin(), vec.end(), hi) - lower_bound(vec.begin(), vec.end(), lo);
if (here) return 1;
}
if (r & 1) {
vector <int> &vec = t[--r];
int here = lower_bound(vec.begin(), vec.end(), hi) - lower_bound(vec.begin(), vec.end(), lo);
if (here) return 1;
}
}
return 0;
}
vector <int> solve (vector <pair <int, int>> pts, vector <tuple <int, int, int, int>> que) {
int n = pts.size(), q = que.size();
sort(pts.begin(), pts.end());
for (int i = 0; i < n; ++i) t[n + i] = {pts[i].second};
for (int i = n - 1; i; --i) merge(t[i << 1].begin(), t[i << 1].end(), t[i << 1 | 1].begin(), t[i << 1 | 1].end(), back_inserter(t[i]));
vector <int> ret;
for (auto &[l_x, r_x, l_y, r_y] : que) {
int l = lower_bound(pts.begin(), pts.end(), make_pair(l_x, -1)) - pts.begin();
int r = lower_bound(pts.begin(), pts.end(), make_pair(r_x, -1)) - pts.begin();
ret.emplace_back(query(n, l, r, l_y, r_y));
}
return ret;
}
vector <int> check_validity (int n, vector <int> ed_x, vector <int> ed_y, vector <int> que_s, vector <int> que_e, vector <int> que_l, vector <int> que_r) {
int m = ed_x.size(), q = que_s.size();
for (int i = 0; i < m; ++i) {
int u = ed_x[i], v = ed_y[i];
g[u].emplace_back(v);
g[v].emplace_back(u);
}
for (int i = 0; i < q; ++i) {
who[que_l[i]].emplace_back(i);
}
for (int i = 0; i < n; ++i) root[i] = i;
for (int i = n - 1; i >= 0; --i) {
set <int> childs;
for (int j : g[i]) if (j >= i) childs.emplace(find(j));
for (int j : childs) p[j] = root[j] = i;
for (int id : who[i]) x_sub[id] = find(que_s[id]);
}
for (int i = 1; i < n; ++i) adj[p[i]].emplace_back(i);
ptr = 0; dfs(x_in, x_out, 0);
for (int i = 0; i < n; ++i) who[i].clear(), adj[i].clear();
for (int i = 0; i < q; ++i) {
who[que_r[i]].emplace_back(i);
}
for (int i = 0; i < n; ++i) root[i] = i;
for (int i = 0; i < n; ++i) {
set <int> childs;
for (int j : g[i]) if (j <= i) childs.emplace(find(j));
for (int j : childs) p[j] = root[j] = i;
for (int id : who[i]) y_sub[id] = find(que_e[id]);
}
for (int i = 0; i < n - 1; ++i) adj[p[i]].emplace_back(i);
ptr = 0; dfs(y_in, y_out, n - 1);
vector <pair <int, int>> pts(n);
for (int i = 0; i < n; ++i) pts[i] = make_pair(x_in[i], y_in[i]);
vector <tuple <int, int, int, int>> que(q);
for (int i = 0; i < q; ++i) que[i] = make_tuple(x_in[x_sub[i]], x_out[x_sub[i]], y_in[y_sub[i]], y_out[y_sub[i]]);
return solve(pts, que);
}
Compilation message
werewolf.cpp: In function 'std::vector<int> solve(std::vector<std::pair<int, int> >, std::vector<std::tuple<int, int, int, int> >)':
werewolf.cpp:39:23: warning: unused variable 'q' [-Wunused-variable]
39 | int n = pts.size(), q = que.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
11 ms |
23792 KB |
Output is correct |
3 |
Correct |
11 ms |
23844 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
11 ms |
23756 KB |
Output is correct |
6 |
Correct |
11 ms |
23800 KB |
Output is correct |
7 |
Correct |
11 ms |
23756 KB |
Output is correct |
8 |
Correct |
11 ms |
23752 KB |
Output is correct |
9 |
Correct |
11 ms |
23820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
11 ms |
23792 KB |
Output is correct |
3 |
Correct |
11 ms |
23844 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
11 ms |
23756 KB |
Output is correct |
6 |
Correct |
11 ms |
23800 KB |
Output is correct |
7 |
Correct |
11 ms |
23756 KB |
Output is correct |
8 |
Correct |
11 ms |
23752 KB |
Output is correct |
9 |
Correct |
11 ms |
23820 KB |
Output is correct |
10 |
Correct |
17 ms |
24908 KB |
Output is correct |
11 |
Correct |
17 ms |
24832 KB |
Output is correct |
12 |
Correct |
16 ms |
24832 KB |
Output is correct |
13 |
Correct |
17 ms |
25076 KB |
Output is correct |
14 |
Correct |
17 ms |
25036 KB |
Output is correct |
15 |
Correct |
18 ms |
24972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
583 ms |
101044 KB |
Output is correct |
2 |
Correct |
449 ms |
104200 KB |
Output is correct |
3 |
Correct |
447 ms |
101876 KB |
Output is correct |
4 |
Correct |
488 ms |
101316 KB |
Output is correct |
5 |
Correct |
513 ms |
101176 KB |
Output is correct |
6 |
Correct |
561 ms |
101428 KB |
Output is correct |
7 |
Correct |
534 ms |
99496 KB |
Output is correct |
8 |
Correct |
441 ms |
104504 KB |
Output is correct |
9 |
Correct |
410 ms |
101572 KB |
Output is correct |
10 |
Correct |
528 ms |
100600 KB |
Output is correct |
11 |
Correct |
575 ms |
100620 KB |
Output is correct |
12 |
Correct |
457 ms |
101020 KB |
Output is correct |
13 |
Correct |
515 ms |
105468 KB |
Output is correct |
14 |
Correct |
550 ms |
105784 KB |
Output is correct |
15 |
Correct |
534 ms |
105628 KB |
Output is correct |
16 |
Correct |
513 ms |
105800 KB |
Output is correct |
17 |
Correct |
500 ms |
99520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
11 ms |
23792 KB |
Output is correct |
3 |
Correct |
11 ms |
23844 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
11 ms |
23756 KB |
Output is correct |
6 |
Correct |
11 ms |
23800 KB |
Output is correct |
7 |
Correct |
11 ms |
23756 KB |
Output is correct |
8 |
Correct |
11 ms |
23752 KB |
Output is correct |
9 |
Correct |
11 ms |
23820 KB |
Output is correct |
10 |
Correct |
17 ms |
24908 KB |
Output is correct |
11 |
Correct |
17 ms |
24832 KB |
Output is correct |
12 |
Correct |
16 ms |
24832 KB |
Output is correct |
13 |
Correct |
17 ms |
25076 KB |
Output is correct |
14 |
Correct |
17 ms |
25036 KB |
Output is correct |
15 |
Correct |
18 ms |
24972 KB |
Output is correct |
16 |
Correct |
583 ms |
101044 KB |
Output is correct |
17 |
Correct |
449 ms |
104200 KB |
Output is correct |
18 |
Correct |
447 ms |
101876 KB |
Output is correct |
19 |
Correct |
488 ms |
101316 KB |
Output is correct |
20 |
Correct |
513 ms |
101176 KB |
Output is correct |
21 |
Correct |
561 ms |
101428 KB |
Output is correct |
22 |
Correct |
534 ms |
99496 KB |
Output is correct |
23 |
Correct |
441 ms |
104504 KB |
Output is correct |
24 |
Correct |
410 ms |
101572 KB |
Output is correct |
25 |
Correct |
528 ms |
100600 KB |
Output is correct |
26 |
Correct |
575 ms |
100620 KB |
Output is correct |
27 |
Correct |
457 ms |
101020 KB |
Output is correct |
28 |
Correct |
515 ms |
105468 KB |
Output is correct |
29 |
Correct |
550 ms |
105784 KB |
Output is correct |
30 |
Correct |
534 ms |
105628 KB |
Output is correct |
31 |
Correct |
513 ms |
105800 KB |
Output is correct |
32 |
Correct |
500 ms |
99520 KB |
Output is correct |
33 |
Correct |
710 ms |
102288 KB |
Output is correct |
34 |
Correct |
259 ms |
64852 KB |
Output is correct |
35 |
Correct |
696 ms |
104772 KB |
Output is correct |
36 |
Correct |
668 ms |
101696 KB |
Output is correct |
37 |
Correct |
692 ms |
103708 KB |
Output is correct |
38 |
Correct |
684 ms |
102244 KB |
Output is correct |
39 |
Correct |
536 ms |
110652 KB |
Output is correct |
40 |
Correct |
652 ms |
108984 KB |
Output is correct |
41 |
Correct |
702 ms |
103232 KB |
Output is correct |
42 |
Correct |
504 ms |
101040 KB |
Output is correct |
43 |
Correct |
634 ms |
108624 KB |
Output is correct |
44 |
Correct |
701 ms |
103652 KB |
Output is correct |
45 |
Correct |
498 ms |
110424 KB |
Output is correct |
46 |
Correct |
458 ms |
110184 KB |
Output is correct |
47 |
Correct |
545 ms |
105660 KB |
Output is correct |
48 |
Correct |
591 ms |
105820 KB |
Output is correct |
49 |
Correct |
583 ms |
105712 KB |
Output is correct |
50 |
Correct |
573 ms |
105828 KB |
Output is correct |
51 |
Correct |
755 ms |
107380 KB |
Output is correct |
52 |
Correct |
723 ms |
107292 KB |
Output is correct |