#include "werewolf.h"
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int LOG = 19;
const int N = 1 << LOG;
struct quest {
int l, r, a, b;
quest() {}
quest(int l, int r, int a, int b) : l(l), r(r), a(a), b(b) {}
};
quest q[N];
vector<int> g[N], h[N];
int un[N], iv[N], ma[N];
int trazi(int u) {
if(un[u] == -1) {
return u;
}
return un[u] = trazi(un[u]);
}
void unija(int u, int v) {
u = trazi(u);
if(u == v) { return; }
un[u] = v;
h[v].PB(u);
}
int up[N][LOG], val[N];
void dfs(int u, vector<int> &p) {
iv[u] = p.size();
for(int v : h[u]) {
up[v][0] = u;
// printf("%d %d\n", u, v);
dfs(v, p);
}
if(h[u].empty()) {
p.PB(u);
}
ma[u] = p.size();
}
int climb(int u, int x, bool f) {
for(int i = LOG - 1; i >= 0; --i) {
if((val[up[u][i]] >= x) == f) {
u = up[u][i];
}
}
return u;
}
int t[2 * N]; // memset -1
void update(int u, int x) {
u += N;
t[u] = x;
for(u >>= 1; u; u >>= 1) {
t[u] = max(t[2 * u], t[2 * u + 1]);
}
}
int query(int l, int r, int u = 1, int lo = 0, int hi = N) {
if(r <= lo || hi <= l) { return -1; }
if(l <= lo && hi <= r) { return t[u]; }
int mi = (lo + hi) / 2;
return max(query(l, r, 2 * u, lo, mi), query(l, r, 2 * u + 1, mi, hi));
}
vector<int> qi[N];
vi check_validity(int n, vi X, vi Y, vi S, vi E, vi L, vi R) {
int m = S.size();
vector<int> ans(m);
for(int i = 0; i < X.size(); ++i) {
g[X[i]].PB(Y[i]);
g[Y[i]].PB(X[i]);
}
// n - 1, n - 2, ... 0
memset(un, -1, sizeof(un));
for(int i = n - 2, j = n; i >= 0; --i, ++j) {
unija(i, j);
val[j] = i;
up[j][0] = j;
for(int v : g[i]) {
if(v > i) {
unija(v, j);
}
}
}
vector<int> a;
dfs(2 * n - 2, a);
for(int i = 1; i < LOG; ++i) { for(int j = 0; j < 2 * n - 1; ++j) { up[j][i] = up[up[j][i - 1]][i - 1]; } }
for(int i = 0; i < m; ++i) {
int res = climb(S[i], L[i], 1);
q[i].l = iv[res];
q[i].r = ma[res];
qi[q[i].r - 1].PB(i);
// printf("%d %d lr %d %d\n", i, res, q[i].l, q[i].r);
}
// 0, 1, ... n - 1
memset(un, -1, sizeof(un));
for(int i = 1, j = n; i < n; ++i, ++j) {
h[j].clear();
unija(i, j);
val[j] = i;
up[j][0] = j;
for(int v : g[i]) {
if(v < i) {
unija(v, j);
}
}
}
vector<int> b;
dfs(2 * n - 2, b);
for(int i = 1; i < LOG; ++i) { for(int j = 0; j < 2 * n - 1; ++j) {
up[j][i] = up[up[j][i - 1]][i - 1]; } }
for(int i = 0; i < m; ++i) {
int res = climb(E[i], R[i] + 1, 0);
q[i].a = iv[res];
q[i].b = ma[res];
// printf("%d %d ab %d %d\n", i, res, q[i].a, q[i].b);
}
// for(int i = 0; i < n; ++i) { printf("(%d, %d)%c", i, a[i], " \n"[i == n - 1]); }
// for(int i = 0; i < n; ++i) { printf("(%d, %d)%c", i, b[i], " \n"[i == n - 1]); }
for(int i = 0; i < n; ++i) {
val[b[i]] = i;
}
memset(t, -1, sizeof(t));
for(int i = 0; i < n; ++i) {
update(val[a[i]], i);
for(int j : qi[i]) {
// printf("%d %d : %d %d %d %d\n", i, j, q[j].a, q[j].b, q[j].l, query(q[j].a, q[j].b + 1));
if(query(q[j].a, q[j].b) >= q[j].l) {
ans[j] = 1;
}
}
}
return ans;
}
Compilation message
werewolf.cpp: In function 'vi check_validity(int, vi, vi, vi, vi, vi, vi)':
werewolf.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int i = 0; i < X.size(); ++i) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
43356 KB |
Output is correct |
2 |
Correct |
19 ms |
43352 KB |
Output is correct |
3 |
Correct |
20 ms |
43356 KB |
Output is correct |
4 |
Correct |
19 ms |
43368 KB |
Output is correct |
5 |
Correct |
24 ms |
43356 KB |
Output is correct |
6 |
Correct |
18 ms |
43432 KB |
Output is correct |
7 |
Correct |
19 ms |
43356 KB |
Output is correct |
8 |
Correct |
18 ms |
43536 KB |
Output is correct |
9 |
Correct |
19 ms |
43352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
43356 KB |
Output is correct |
2 |
Correct |
19 ms |
43352 KB |
Output is correct |
3 |
Correct |
20 ms |
43356 KB |
Output is correct |
4 |
Correct |
19 ms |
43368 KB |
Output is correct |
5 |
Correct |
24 ms |
43356 KB |
Output is correct |
6 |
Correct |
18 ms |
43432 KB |
Output is correct |
7 |
Correct |
19 ms |
43356 KB |
Output is correct |
8 |
Correct |
18 ms |
43536 KB |
Output is correct |
9 |
Correct |
19 ms |
43352 KB |
Output is correct |
10 |
Correct |
23 ms |
44632 KB |
Output is correct |
11 |
Correct |
23 ms |
44648 KB |
Output is correct |
12 |
Correct |
23 ms |
44632 KB |
Output is correct |
13 |
Correct |
23 ms |
44636 KB |
Output is correct |
14 |
Correct |
23 ms |
44632 KB |
Output is correct |
15 |
Correct |
23 ms |
44636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
465 ms |
115776 KB |
Output is correct |
2 |
Correct |
426 ms |
119624 KB |
Output is correct |
3 |
Correct |
430 ms |
116556 KB |
Output is correct |
4 |
Correct |
402 ms |
115484 KB |
Output is correct |
5 |
Correct |
422 ms |
115284 KB |
Output is correct |
6 |
Correct |
452 ms |
115540 KB |
Output is correct |
7 |
Correct |
409 ms |
115340 KB |
Output is correct |
8 |
Correct |
410 ms |
119628 KB |
Output is correct |
9 |
Correct |
365 ms |
117360 KB |
Output is correct |
10 |
Correct |
347 ms |
115040 KB |
Output is correct |
11 |
Correct |
342 ms |
115912 KB |
Output is correct |
12 |
Correct |
367 ms |
115916 KB |
Output is correct |
13 |
Correct |
424 ms |
122060 KB |
Output is correct |
14 |
Correct |
412 ms |
121912 KB |
Output is correct |
15 |
Correct |
452 ms |
122084 KB |
Output is correct |
16 |
Correct |
408 ms |
121928 KB |
Output is correct |
17 |
Correct |
411 ms |
115332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
43356 KB |
Output is correct |
2 |
Correct |
19 ms |
43352 KB |
Output is correct |
3 |
Correct |
20 ms |
43356 KB |
Output is correct |
4 |
Correct |
19 ms |
43368 KB |
Output is correct |
5 |
Correct |
24 ms |
43356 KB |
Output is correct |
6 |
Correct |
18 ms |
43432 KB |
Output is correct |
7 |
Correct |
19 ms |
43356 KB |
Output is correct |
8 |
Correct |
18 ms |
43536 KB |
Output is correct |
9 |
Correct |
19 ms |
43352 KB |
Output is correct |
10 |
Correct |
23 ms |
44632 KB |
Output is correct |
11 |
Correct |
23 ms |
44648 KB |
Output is correct |
12 |
Correct |
23 ms |
44632 KB |
Output is correct |
13 |
Correct |
23 ms |
44636 KB |
Output is correct |
14 |
Correct |
23 ms |
44632 KB |
Output is correct |
15 |
Correct |
23 ms |
44636 KB |
Output is correct |
16 |
Correct |
465 ms |
115776 KB |
Output is correct |
17 |
Correct |
426 ms |
119624 KB |
Output is correct |
18 |
Correct |
430 ms |
116556 KB |
Output is correct |
19 |
Correct |
402 ms |
115484 KB |
Output is correct |
20 |
Correct |
422 ms |
115284 KB |
Output is correct |
21 |
Correct |
452 ms |
115540 KB |
Output is correct |
22 |
Correct |
409 ms |
115340 KB |
Output is correct |
23 |
Correct |
410 ms |
119628 KB |
Output is correct |
24 |
Correct |
365 ms |
117360 KB |
Output is correct |
25 |
Correct |
347 ms |
115040 KB |
Output is correct |
26 |
Correct |
342 ms |
115912 KB |
Output is correct |
27 |
Correct |
367 ms |
115916 KB |
Output is correct |
28 |
Correct |
424 ms |
122060 KB |
Output is correct |
29 |
Correct |
412 ms |
121912 KB |
Output is correct |
30 |
Correct |
452 ms |
122084 KB |
Output is correct |
31 |
Correct |
408 ms |
121928 KB |
Output is correct |
32 |
Correct |
411 ms |
115332 KB |
Output is correct |
33 |
Correct |
493 ms |
117504 KB |
Output is correct |
34 |
Correct |
210 ms |
79072 KB |
Output is correct |
35 |
Correct |
524 ms |
120552 KB |
Output is correct |
36 |
Correct |
490 ms |
116552 KB |
Output is correct |
37 |
Correct |
575 ms |
119616 KB |
Output is correct |
38 |
Correct |
526 ms |
117324 KB |
Output is correct |
39 |
Correct |
470 ms |
129092 KB |
Output is correct |
40 |
Correct |
526 ms |
126160 KB |
Output is correct |
41 |
Correct |
428 ms |
118492 KB |
Output is correct |
42 |
Correct |
367 ms |
115548 KB |
Output is correct |
43 |
Correct |
507 ms |
124252 KB |
Output is correct |
44 |
Correct |
474 ms |
119116 KB |
Output is correct |
45 |
Correct |
387 ms |
129188 KB |
Output is correct |
46 |
Correct |
429 ms |
128092 KB |
Output is correct |
47 |
Correct |
401 ms |
122316 KB |
Output is correct |
48 |
Correct |
425 ms |
122056 KB |
Output is correct |
49 |
Correct |
447 ms |
122080 KB |
Output is correct |
50 |
Correct |
412 ms |
122184 KB |
Output is correct |
51 |
Correct |
500 ms |
125668 KB |
Output is correct |
52 |
Correct |
546 ms |
125556 KB |
Output is correct |