#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '"' << x << '"'; } void __print(const string& x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define ln "\n"
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define ar array
int Bit(int mask, int b) { return (mask >> b) & 1; }
const ll base = 311, MOD = 998244353, M = 1e9 + 7, INF = 1e18;
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R) {
int Q = S.size();
int M = X.size();
std::vector<int> ANS(Q);
vector<vector<int>> adj(N);
rep(i, 0, M - 1) {
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
if (N <= 3000) {
rep(i, 0, Q - 1) {
vector<int> vis(N, 0);
int ok = 0;
auto dfs = [&](auto self, int u, int lb, int ub) -> void {
if (u < lb || u > ub) return;
vis[u] = (ub == 1e8 ? 1 : 2);
for (int v : adj[u])
if (!vis[v]) {
if (lb <= v && v <= ub)
self(self, v, lb, ub);
}
else {
if (lb == -1 && vis[v] == 1 && v <= R[i])
ok = 1;
}
};
dfs(dfs, S[i], L[i], 1e8);
if (E[i] <= R[i] && vis[E[i]] == 1)
ok = true;
dfs(dfs, E[i], -1, R[i]);
ANS[i] = ok;
}
return ANS;
}
vector<int> pos(N);
int dtime = -1;
auto dfs = [&](auto self, int u, int p) -> void {
pos[u] = ++dtime;
for (int v : adj[u]) if (v != p)
self(self, v, u);
};
rep(i, 0, N - 1) if (adj[i].size() == 1) {
dfs(dfs, i, -1);
break;
}
vector<int> a(N, 0);
iota(all(a), 0);
sort(all(a), [&](int i, int j) {
return pos[i] < pos[j];
});
struct Info {
int min = 1e9;
int max = -1e9;
Info operator + (const Info& p) {
return Info{ std::min(min, p.min), std::max(max, p.max) };
}
};
vector<vector<Info>> g(N, vector<Info>(21));
for (int i = 0; i < N; ++i)
g[i][0] = { a[i], a[i] };
for (int j = 1; j < 21; ++j)
for (int i = 0; i + (1 << j) <= N; ++i)
g[i][j] = g[i][j - 1] + g[i + (1 << (j - 1))][j - 1];
auto get = [&](int l, int r) -> Info {
int k = log2(r - l + 1);
return g[l][k] + g[r - (1 << k) + 1][k];
};
rep(i, 0, Q - 1) {
if (S[i] < L[i] || E[i] > R[i]) continue;
if (pos[S[i]] < pos[E[i]]) {
// min(pos[si], mid) >= L
// max(mid, pos[ei]) <= R
int lo = pos[S[i]], hi = pos[E[i]], md;
int x = lo;
while (lo <= hi) {
md = (lo + hi) / 2;
if (get(pos[S[i]], md).min >= L[i]) {
lo = md + 1;
x = max(x, md);
}
else
hi = md - 1;
}
ANS[i] = get(x, pos[E[i]]).max <= R[i];
}
else {
// min(mid, pos[si]) >= L
// max(pos[ei], mid) <= R
int lo = pos[E[i]], hi = pos[S[i]], md;
int x = hi;
while (lo <= hi) {
md = (lo + hi) / 2;
if (get(md, pos[S[i]]).min >= L[i]) {
hi = md - 1;
x = min(x, md);
}
else
lo = md + 1;
}
ANS[i] = get(pos[E[i]], x).max <= R[i];
}
}
return ANS;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
133 ms |
912 KB |
Output is correct |
11 |
Correct |
70 ms |
856 KB |
Output is correct |
12 |
Correct |
8 ms |
860 KB |
Output is correct |
13 |
Correct |
172 ms |
708 KB |
Output is correct |
14 |
Correct |
118 ms |
856 KB |
Output is correct |
15 |
Correct |
163 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
386 ms |
77312 KB |
Output is correct |
2 |
Correct |
313 ms |
77332 KB |
Output is correct |
3 |
Correct |
322 ms |
77324 KB |
Output is correct |
4 |
Correct |
353 ms |
77140 KB |
Output is correct |
5 |
Correct |
355 ms |
77140 KB |
Output is correct |
6 |
Correct |
361 ms |
77144 KB |
Output is correct |
7 |
Correct |
369 ms |
77140 KB |
Output is correct |
8 |
Correct |
303 ms |
77140 KB |
Output is correct |
9 |
Correct |
221 ms |
77196 KB |
Output is correct |
10 |
Correct |
234 ms |
77140 KB |
Output is correct |
11 |
Correct |
254 ms |
77140 KB |
Output is correct |
12 |
Correct |
255 ms |
77192 KB |
Output is correct |
13 |
Correct |
361 ms |
77140 KB |
Output is correct |
14 |
Correct |
370 ms |
77320 KB |
Output is correct |
15 |
Correct |
366 ms |
77136 KB |
Output is correct |
16 |
Correct |
345 ms |
77328 KB |
Output is correct |
17 |
Correct |
345 ms |
77140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
133 ms |
912 KB |
Output is correct |
11 |
Correct |
70 ms |
856 KB |
Output is correct |
12 |
Correct |
8 ms |
860 KB |
Output is correct |
13 |
Correct |
172 ms |
708 KB |
Output is correct |
14 |
Correct |
118 ms |
856 KB |
Output is correct |
15 |
Correct |
163 ms |
888 KB |
Output is correct |
16 |
Correct |
386 ms |
77312 KB |
Output is correct |
17 |
Correct |
313 ms |
77332 KB |
Output is correct |
18 |
Correct |
322 ms |
77324 KB |
Output is correct |
19 |
Correct |
353 ms |
77140 KB |
Output is correct |
20 |
Correct |
355 ms |
77140 KB |
Output is correct |
21 |
Correct |
361 ms |
77144 KB |
Output is correct |
22 |
Correct |
369 ms |
77140 KB |
Output is correct |
23 |
Correct |
303 ms |
77140 KB |
Output is correct |
24 |
Correct |
221 ms |
77196 KB |
Output is correct |
25 |
Correct |
234 ms |
77140 KB |
Output is correct |
26 |
Correct |
254 ms |
77140 KB |
Output is correct |
27 |
Correct |
255 ms |
77192 KB |
Output is correct |
28 |
Correct |
361 ms |
77140 KB |
Output is correct |
29 |
Correct |
370 ms |
77320 KB |
Output is correct |
30 |
Correct |
366 ms |
77136 KB |
Output is correct |
31 |
Correct |
345 ms |
77328 KB |
Output is correct |
32 |
Correct |
345 ms |
77140 KB |
Output is correct |
33 |
Incorrect |
352 ms |
70736 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |