#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
refs:
edi
*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
const int LOG = 18;
#include "werewolf.h"
struct DSU {
vector<int> par, rankk, siz, mn, mx;
DSU() {
}
DSU(int n) {
init(n);
}
void init(int n) {
par = vector<int>(n + 1);
rankk = vector<int>(n + 1);
siz = vector<int>(n + 1);
mn = vector<int>(n + 1);
mx = vector<int>(n + 1);
rep(i, n + 1) create(i);
}
void create(int u) {
par[u] = u;
rankk[u] = 0;
siz[u] = 1;
mn[u] = u;
mx[u] = u;
}
int find(int u) {
if (u == par[u]) return u;
else return par[u] = find(par[u]);
}
bool same(int u, int v) {
return find(u) == find(v);
}
void merge(int u, int v) {
u = find(u), v = find(v);
if (u == v) return;
if (rankk[u] == rankk[v]) rankk[u]++;
if (rankk[u] < rankk[v]) swap(u, v);
par[v] = u;
siz[u] += siz[v];
amin(mn[u],mn[v]);
amax(mx[u],mx[v]);
}
};
vector<int> adjg[N], adj1[N], adj2[N];
vector<int> tin1(N), tout1(N), subsiz1(N);
vector<int> tin2(N), tout2(N), subsiz2(N);
int up1[N][LOG], up2[N][LOG];
int timer;
void dfs1(int u){
tin1[u] = timer++;
subsiz1[u] = 1;
trav(v,adj1[u]){
up1[v][0] = u;
rep1(j,LOG-1){
up1[v][j] = up1[up1[v][j-1]][j-1];
}
dfs1(v);
subsiz1[u] += subsiz1[v];
}
tout1[u] = timer++;
}
void dfs2(int u){
tin2[u] = timer++;
subsiz2[u] = 1;
trav(v,adj2[u]){
up2[v][0] = u;
rep1(j,LOG-1){
up2[v][j] = up2[up2[v][j-1]][j-1];
}
dfs2(v);
subsiz2[u] += subsiz2[v];
}
tout2[u] = timer++;
}
set<ll> st[N];
vector<array<int,3>> queries_here[N];
vector<int> ans;
void dfs3(int u){
pii big = {-1,-1};
trav(v,adj1[u]){
pii px = {subsiz1[v],v};
amax(big,px);
}
int heavy = big.ss;
if(heavy != -1){
dfs3(heavy);
swap(st[u],st[heavy]);
}
trav(v,adj1[u]){
if(v == heavy) conts;
dfs3(v);
trav(x,st[v]){
st[u].insert(x);
}
st[v].clear();
}
st[u].insert(tin2[u]);
for(auto [l,r,id] : queries_here[u]){
auto it = st[u].lower_bound(l);
if(it != st[u].end()){
if(*it <= r){
ans[id] = 1;
}
}
}
}
std::vector<int> check_validity(int n, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> T,
std::vector<int> L, std::vector<int> R) {
int m = sz(X), q = sz(S);
rep(i,m){
int u = X[i], v = Y[i];
adjg[u].pb(v), adjg[v].pb(u);
}
DSU dsu(n);
rev(u,n-1,0){
trav(v,adjg[u]){
if(u <= v){
if(!dsu.same(u,v)){
int cc = dsu.find(v);
int mn = dsu.mn[cc];
adj1[u].pb(mn);
dsu.merge(u,v);
}
}
}
}
dsu = DSU(n);
rep(u,n){
trav(v,adjg[u]){
if(u >= v){
if(!dsu.same(u,v)){
int cc = dsu.find(v);
int mx = dsu.mx[cc];
adj2[u].pb(mx);
dsu.merge(u,v);
}
}
}
}
rep(j,LOG) up1[0][j] = 0;
timer = 1;
dfs1(0);
rep(j,LOG) up2[n-1][j] = n-1;
timer = 1;
dfs2(n-1);
ans = vector<int>(q);
rep(i,q){
int s = S[i], t = T[i], l = L[i], r = R[i];
rev(j,LOG-1,0){
if(up1[s][j] >= l){
s = up1[s][j];
}
}
rev(j,LOG-1,0){
if(up2[t][j] <= r){
t = up2[t][j];
}
}
queries_here[s].pb({tin2[t],tout2[t],i});
}
dfs3(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
36696 KB |
Output is correct |
2 |
Correct |
9 ms |
36700 KB |
Output is correct |
3 |
Correct |
8 ms |
36700 KB |
Output is correct |
4 |
Correct |
11 ms |
36700 KB |
Output is correct |
5 |
Correct |
9 ms |
36696 KB |
Output is correct |
6 |
Correct |
9 ms |
36700 KB |
Output is correct |
7 |
Correct |
9 ms |
36700 KB |
Output is correct |
8 |
Correct |
10 ms |
36856 KB |
Output is correct |
9 |
Correct |
8 ms |
36928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
36696 KB |
Output is correct |
2 |
Correct |
9 ms |
36700 KB |
Output is correct |
3 |
Correct |
8 ms |
36700 KB |
Output is correct |
4 |
Correct |
11 ms |
36700 KB |
Output is correct |
5 |
Correct |
9 ms |
36696 KB |
Output is correct |
6 |
Correct |
9 ms |
36700 KB |
Output is correct |
7 |
Correct |
9 ms |
36700 KB |
Output is correct |
8 |
Correct |
10 ms |
36856 KB |
Output is correct |
9 |
Correct |
8 ms |
36928 KB |
Output is correct |
10 |
Correct |
13 ms |
37468 KB |
Output is correct |
11 |
Correct |
13 ms |
37476 KB |
Output is correct |
12 |
Correct |
14 ms |
37468 KB |
Output is correct |
13 |
Correct |
13 ms |
37720 KB |
Output is correct |
14 |
Correct |
14 ms |
37724 KB |
Output is correct |
15 |
Correct |
15 ms |
37720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
106060 KB |
Output is correct |
2 |
Correct |
526 ms |
109676 KB |
Output is correct |
3 |
Correct |
419 ms |
113948 KB |
Output is correct |
4 |
Correct |
469 ms |
112520 KB |
Output is correct |
5 |
Correct |
477 ms |
112712 KB |
Output is correct |
6 |
Correct |
600 ms |
114448 KB |
Output is correct |
7 |
Correct |
541 ms |
114752 KB |
Output is correct |
8 |
Correct |
447 ms |
117896 KB |
Output is correct |
9 |
Correct |
381 ms |
113664 KB |
Output is correct |
10 |
Correct |
381 ms |
112268 KB |
Output is correct |
11 |
Correct |
429 ms |
111944 KB |
Output is correct |
12 |
Correct |
445 ms |
112392 KB |
Output is correct |
13 |
Correct |
507 ms |
134912 KB |
Output is correct |
14 |
Correct |
524 ms |
135124 KB |
Output is correct |
15 |
Correct |
537 ms |
135420 KB |
Output is correct |
16 |
Correct |
498 ms |
134964 KB |
Output is correct |
17 |
Correct |
588 ms |
115724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
36696 KB |
Output is correct |
2 |
Correct |
9 ms |
36700 KB |
Output is correct |
3 |
Correct |
8 ms |
36700 KB |
Output is correct |
4 |
Correct |
11 ms |
36700 KB |
Output is correct |
5 |
Correct |
9 ms |
36696 KB |
Output is correct |
6 |
Correct |
9 ms |
36700 KB |
Output is correct |
7 |
Correct |
9 ms |
36700 KB |
Output is correct |
8 |
Correct |
10 ms |
36856 KB |
Output is correct |
9 |
Correct |
8 ms |
36928 KB |
Output is correct |
10 |
Correct |
13 ms |
37468 KB |
Output is correct |
11 |
Correct |
13 ms |
37476 KB |
Output is correct |
12 |
Correct |
14 ms |
37468 KB |
Output is correct |
13 |
Correct |
13 ms |
37720 KB |
Output is correct |
14 |
Correct |
14 ms |
37724 KB |
Output is correct |
15 |
Correct |
15 ms |
37720 KB |
Output is correct |
16 |
Correct |
597 ms |
106060 KB |
Output is correct |
17 |
Correct |
526 ms |
109676 KB |
Output is correct |
18 |
Correct |
419 ms |
113948 KB |
Output is correct |
19 |
Correct |
469 ms |
112520 KB |
Output is correct |
20 |
Correct |
477 ms |
112712 KB |
Output is correct |
21 |
Correct |
600 ms |
114448 KB |
Output is correct |
22 |
Correct |
541 ms |
114752 KB |
Output is correct |
23 |
Correct |
447 ms |
117896 KB |
Output is correct |
24 |
Correct |
381 ms |
113664 KB |
Output is correct |
25 |
Correct |
381 ms |
112268 KB |
Output is correct |
26 |
Correct |
429 ms |
111944 KB |
Output is correct |
27 |
Correct |
445 ms |
112392 KB |
Output is correct |
28 |
Correct |
507 ms |
134912 KB |
Output is correct |
29 |
Correct |
524 ms |
135124 KB |
Output is correct |
30 |
Correct |
537 ms |
135420 KB |
Output is correct |
31 |
Correct |
498 ms |
134964 KB |
Output is correct |
32 |
Correct |
588 ms |
115724 KB |
Output is correct |
33 |
Correct |
581 ms |
114820 KB |
Output is correct |
34 |
Correct |
190 ms |
72216 KB |
Output is correct |
35 |
Correct |
565 ms |
121632 KB |
Output is correct |
36 |
Correct |
598 ms |
114928 KB |
Output is correct |
37 |
Correct |
563 ms |
119708 KB |
Output is correct |
38 |
Correct |
551 ms |
116092 KB |
Output is correct |
39 |
Correct |
546 ms |
129976 KB |
Output is correct |
40 |
Correct |
540 ms |
130400 KB |
Output is correct |
41 |
Correct |
471 ms |
117804 KB |
Output is correct |
42 |
Correct |
451 ms |
113408 KB |
Output is correct |
43 |
Correct |
605 ms |
129588 KB |
Output is correct |
44 |
Correct |
493 ms |
119644 KB |
Output is correct |
45 |
Correct |
468 ms |
128924 KB |
Output is correct |
46 |
Correct |
508 ms |
129020 KB |
Output is correct |
47 |
Correct |
659 ms |
135616 KB |
Output is correct |
48 |
Correct |
569 ms |
135048 KB |
Output is correct |
49 |
Correct |
556 ms |
135388 KB |
Output is correct |
50 |
Correct |
591 ms |
135056 KB |
Output is correct |
51 |
Correct |
511 ms |
130468 KB |
Output is correct |
52 |
Correct |
534 ms |
130440 KB |
Output is correct |