이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 2e5 + 10;
const int lg = 20;
int n, m, q, st[maxn], en[maxn], ver[maxn], tme, dsu[maxn], par[maxn][lg], comp[maxn];
vector<int> g[maxn], t[maxn];
set<int> val[maxn];
struct Query{
int l, s, e, idx;
};
vector<Query> Q[maxn];
int getdsu(int v){
return (dsu[v] == -1? v: dsu[v] = getdsu(dsu[v]));
}
void merge(int u, int v){
if ((u = getdsu(u)) == (v = getdsu(v))) return;
if (u < v) swap(u, v);
dsu[u] = v;
t[v].push_back(u);
//debug(v, u);
}
void dfs(int v, int p = -1){
st[v] = ++tme;
ver[tme] = v;
par[v][0] = p;
for (int i = 1; i < lg; i++){
if (par[v][i-1] != -1) par[v][i] = par[par[v][i-1]][i-1];
}
for (auto u: t[v]){
dfs(u, v);
}
en[v] = tme;
//debug(v, st[v], en[v]);
//for (int i = 0; i < lg; i++) debug(i, par[v][i]);
}
void merge2(int u, int v){
if ((u = comp[u]) == (v = comp[v])) return;
//debug(u, v);
if (val[u].size() > val[v].size()) swap(u, v);
for (auto x: val[u]){
if (ver[x] == u) continue;
val[v].insert(x);
comp[ver[x]] = v;
}
val[u].clear();
comp[u] = comp[v];
val[v].insert(st[u]);
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R){
memset(dsu, -1, sizeof dsu);
memset(par, -1, sizeof par);
n = N;
m = X.size();
q = S.size();
for (int i = 0; i < m; i++){
// debug(X[i], Y[i]);
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
for (int i = 0; i < q; i++){
// debug(L[i], R[i], S[i], E[i]);
Q[R[i]].push_back({L[i], S[i], E[i], i});
}
for (int i = n-1; ~i; i--){
for (auto u: g[i]){
if (u > i) merge(u, i);
}
}
dfs(0);
vector<int> ans(q);
for (int i = 0; i < n; i++){
//debug(i, st[i]);
comp[i] = i;
val[i].insert(st[i]);
for (auto u: g[i]){
if (u < i) merge2(u, i);
}
for (auto x : Q[i]){
// debug(x.l, x.s, x.e, x.idx);
int v = x.s;
for (int j = lg-1; ~j; j--){
if (par[v][j] >= x.l) v = par[v][j];
}
// debug(v, st[v], en[v]);
// debug(comp[x.e]);
auto it = val[comp[x.e]].lower_bound(st[v]);
if (it != val[comp[x.e]].end() && (*it) <= en[v]){
ans[x.idx] = 1;
//debug((*it));
}
else ans[x.idx] = 0;
}
}
return ans;
}
# | 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... |