This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
struct Sparse1 {
int n;
int LOG;
vector<vector<int>> table;
Sparse1(vector<int>& a) {
n = a.size();
LOG = (int)(log2(n)) + 1;
table = vector<vector<int>>(n, vector<int>(LOG));
for(int i = 0; i < n; ++i) {
table[i][0] = a[i];
}
for(int j = 1; j < LOG; ++j) {
for(int i = 0; i + (1 << j) <= n; ++i) {
table[i][j] = min(table[i][j - 1], table[(1 << (j - 1)) + i][j - 1]);
}
}
}
int get(int low, int high) {
int sz = (high - low + 1);
int l = log2(sz);
return min(table[low][l], table[high - (1 << l) + 1][l]);
}
};
struct Sparse2 {
int n;
int LOG;
vector<vector<int>> table;
Sparse2(vector<int>& a) {
n = a.size();
LOG = (int)(log2(n)) + 1;
table = vector<vector<int>>(n, vector<int>(LOG));
for(int i = 0; i < n; ++i) {
table[i][0] = a[i];
}
for(int j = 1; j < LOG; ++j) {
for(int i = 0; i + (1 << j) <= n; ++i) {
table[i][j] = max(table[i][j - 1], table[(1 << (j - 1)) + i][j - 1]);
}
}
}
int get(int low, int high) {
int sz = (high - low + 1);
int l = log2(sz);
return max(table[low][l], table[high - (1 << l) + 1][l]);
}
};
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();
vector<int> a(q);
vector<vector<int>> adj(n);
for(int i = 0; i < x.size(); ++i) {
adj[x[i]].push_back(y[i]);
adj[y[i]].push_back(x[i]);
}
int root = 0;
for(int i = 0; i < n; ++i) {
if(adj.size() == 1) {
root = i;
break;
}
}
vector<int> arr;
vector<int> inv(n);
function<void(int, int)> build = [&](int node, int p = -1) {
inv[node] = (int)arr.size();
arr.push_back(node);
for(int x : adj[node]) {
if(p == x) continue;
build(x, node);
}
};
build(root, -1);
Sparse1 mn(arr);
Sparse2 mx(arr);
for(int i = 0; i < q; ++i) {
int s_l = inv[s[i]];
int s_r = inv[e[i]];
if(l <= r) {
int low = s_l, high = s_r; // max to human
while(low < high) {
int mid = (low + high) / 2;
if(mn.get(s_l, mid) >= l[i]) {
low = mid;
} else {
high = mid - 1;
}
}
int f = low;
low = s_l, high = s_r; // max to human
while(low < high) {
int mid = (low + high + 1) / 2;
if(mx.get(mid, s_r) <= r[i]) {
low = mid;
} else {
high = mid - 1;
}
}
int s = high;
if(s <= f) {
a[i] = 1;
}
}
else {
int low = s_l, high = s_r; // max to human
while(low < high) {
int mid = (low + high) / 2;
if(mn.get(mid, s_r) >= l[i]) {
high = mid;
} else {
low = mid + 1;
}
}
int s = high;
low = l[i], high = r[i]; // max to wolf
while(low < high) {
int mid = (low + high + 1) / 2;
if(mx.get(s_l, mid) <= r[i]) {
low = mid;
} else {
high = mid - 1;
}
}
int f = low;
if(s <= f) {
a[i] = 1;
}
}
}
return a;
}
Compilation message (stderr)
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < x.size(); ++i) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |