#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
template<typename T>
struct SparseTable {
vector<vector<T>> st;
T (*F) (T, T);
int len;
void init(vector<T> &a, T(*f)(T, T)) {
len = (int)a.size();
int mxpow = 32 - __builtin_clz(len);
F = f;
st.resize(mxpow);
st[0] = a;
for(int k = 1; k < mxpow; k++) {
st[k].resize(len - (1 << k) + 1);
for(int i = 0; i < (int)st[k].size(); i++)
st[k][i] = F(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
}
}
T get(int l, int r) {
if(l > r || l < 0 || r >= len) {
exit(1);
}
int k = 31 - __builtin_clz(r - l + 1);
return F(st[k][l], st[k][r - (1 << k) + 1]);
}
};
int n, m, q;
const int N = 2e5 + 10;
vector<int> g[N];
vector<int> cnt;
vector<bool> us;
void dfs(int s, int l, int r) {
us[s] = 1;
cnt[s]++;
for(int to : g[s]) {
if(us[to] || to > r || to < l) continue;
dfs(to, l, r);
}
}
vector<int> order;
int tin[N];
void tour(int s, int p) {
tin[s] = (int)order.size();
order.push_back(s);
for(int to : g[s])
if(to != p)
tour(to, s);
}
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, m = (int)X.size(), q = (int)S.size();
vector<int> res(q);
for(int i = 0; i < m; i++) {
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
if(n <= 3000 && q <= 3000 && m <= 6000) {
for(int i = 0; i < q; i++) {
cnt.assign(n, 0);
us.assign(n, false);
dfs(S[i], L[i], n - 1);
us.assign(n, false);
dfs(E[i], 0, R[i]);
if(*max_element(cnt.begin(), cnt.end()) > 1)
res[i] = 1;
}
return res;
}
int root = 0;
while(root < n && g[root].size() > 1) root++;
tour(root, root);
SparseTable<int> mn, mx;
mn.init(order, [](int a, int b) {return (a > b ? b : a);});
mx.init(order, [](int a, int b) {return (a < b ? b : a);});
for(int i = 0; i < q; i++) {
int x = tin[S[i]], y = tin[E[i]], lb, rb;
int sl, sr, el, er;
lb = x, rb = n;
while(rb - lb > 1) {
int mid = (lb + rb) / 2;
if(mn.get(x, mid) >= L[i]) lb = mid;
else rb = mid;
}
sr = lb;
lb = -1, rb = x;
while(rb - lb > 1) {
int mid = (lb + rb) / 2;
if(mn.get(mid, x) >= L[i]) rb = mid;
else lb = mid;
}
sl = rb;
lb = y, rb = n;
while(rb - lb > 1) {
int mid = (lb + rb) / 2;
if(mx.get(y, mid) <= R[i]) lb = mid;
else rb = mid;
}
er = lb;
lb = -1, rb = y;
while(rb - lb > 1) {
int mid = (lb + rb) / 2;
if(mx.get(mid, y) <= R[i]) rb = mid;
else lb = mid;
}
el = rb;
int ll = max(sl, el), rr = min(sr, er);
res[i] = (ll <= rr);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5004 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5004 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
214 ms |
5272 KB |
Output is correct |
11 |
Correct |
106 ms |
5240 KB |
Output is correct |
12 |
Correct |
23 ms |
5332 KB |
Output is correct |
13 |
Correct |
232 ms |
5276 KB |
Output is correct |
14 |
Correct |
148 ms |
5260 KB |
Output is correct |
15 |
Correct |
188 ms |
5396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1319 ms |
58640 KB |
Output is correct |
2 |
Correct |
427 ms |
58644 KB |
Output is correct |
3 |
Correct |
479 ms |
58644 KB |
Output is correct |
4 |
Correct |
588 ms |
67116 KB |
Output is correct |
5 |
Correct |
588 ms |
67048 KB |
Output is correct |
6 |
Correct |
1010 ms |
67036 KB |
Output is correct |
7 |
Correct |
732 ms |
67048 KB |
Output is correct |
8 |
Correct |
413 ms |
67036 KB |
Output is correct |
9 |
Correct |
335 ms |
67060 KB |
Output is correct |
10 |
Correct |
369 ms |
67036 KB |
Output is correct |
11 |
Correct |
392 ms |
67024 KB |
Output is correct |
12 |
Correct |
364 ms |
67056 KB |
Output is correct |
13 |
Correct |
505 ms |
67048 KB |
Output is correct |
14 |
Correct |
493 ms |
67048 KB |
Output is correct |
15 |
Correct |
444 ms |
67008 KB |
Output is correct |
16 |
Correct |
445 ms |
67020 KB |
Output is correct |
17 |
Correct |
674 ms |
67052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5004 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
214 ms |
5272 KB |
Output is correct |
11 |
Correct |
106 ms |
5240 KB |
Output is correct |
12 |
Correct |
23 ms |
5332 KB |
Output is correct |
13 |
Correct |
232 ms |
5276 KB |
Output is correct |
14 |
Correct |
148 ms |
5260 KB |
Output is correct |
15 |
Correct |
188 ms |
5396 KB |
Output is correct |
16 |
Correct |
1319 ms |
58640 KB |
Output is correct |
17 |
Correct |
427 ms |
58644 KB |
Output is correct |
18 |
Correct |
479 ms |
58644 KB |
Output is correct |
19 |
Correct |
588 ms |
67116 KB |
Output is correct |
20 |
Correct |
588 ms |
67048 KB |
Output is correct |
21 |
Correct |
1010 ms |
67036 KB |
Output is correct |
22 |
Correct |
732 ms |
67048 KB |
Output is correct |
23 |
Correct |
413 ms |
67036 KB |
Output is correct |
24 |
Correct |
335 ms |
67060 KB |
Output is correct |
25 |
Correct |
369 ms |
67036 KB |
Output is correct |
26 |
Correct |
392 ms |
67024 KB |
Output is correct |
27 |
Correct |
364 ms |
67056 KB |
Output is correct |
28 |
Correct |
505 ms |
67048 KB |
Output is correct |
29 |
Correct |
493 ms |
67048 KB |
Output is correct |
30 |
Correct |
444 ms |
67008 KB |
Output is correct |
31 |
Correct |
445 ms |
67020 KB |
Output is correct |
32 |
Correct |
674 ms |
67052 KB |
Output is correct |
33 |
Incorrect |
1103 ms |
57880 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |