欢迎光临
我们一直在努力

PLCT检查是什么[LCT刷题][树链信息维护] P4332 [SHOI2014]三叉神经树

#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int long long
#define endl ' '
using namespace std;

const int N = 3e6 + 10;

int n = 0;

namespace LCT{
struct Info{
short in, out;
int id1, id2, add_tag;
void activate() { out = (in >= 2); }
}tree[N];
int ch[N][2], f[N], tag[N];

#define ls ch[x][0]
#define rs ch[x][1]

inline void push_reverse(int x) { swap(ls, rs), tag[x] ^= 1; }

inline void push_add(int x, int c) {
tree[x].in += c;
tree[x].add_tag += c;
tree[x].activate();
swap(tree[x].id1, tree[x].id2);
}

inline void push_down(int x)
if (tree[x].add_tag)
}

inline void push_up(int x)
if(!tree[x].id2)
}

#define get(x) (ch[f[x]][1] == x)
#define isRoot(x) (ch[f[x]][0] != x && ch[f[x]][1] != x)

void rotate(int x)

void update(int x)

void splay(int x)
push_up(x);
}

int access(int x) {
int p;
for(p = 0; x; x = f[p = x]) splay(x), rs = p, push_up(x);
return p;
}

void makeRoot(int x) { access(x), splay(x), push_reverse(x); }

int findRoot(int x) {
access(x), splay(x);
while(ch[x][0]) push_down(x), x = ch[x][0];
splay(x);
return x;
}

void split(int x, int y) {
makeRoot(x);
access(y), splay(y);
}

void link(int x, int y)

void cut(int x, int y)
}
}

using LCT::tree;

vector<int> g[N];

void dfs(int u) {
for(auto v : g[u]) {
dfs(v);
tree[u].in += tree[v].out;
}
if(u <= n) tree[u].activate();
// cout << "The output of node " << u << " is " << tree[u].out << endl;
}

inline void solve(){
cin >> n;
for(int i = 1; i <= n; i++) {
int x1, x2, x3; cin >> x1 >> x2 >> x3;
g[i].emplace_back(x1), LCT::f[x1] = i;
g[i].emplace_back(x2), LCT::f[x2] = i;
g[i].emplace_back(x3), LCT::f[x3] = i;
}
for(int i = n + 1; i <= 3 * n + 1; i++) cin >> tree[i].out;
dfs(1);
int q, ans = tree[1].out; cin >> q;
while(q--) else {
LCT::push_add(xfa, add_val);
LCT::push_up(xfa);
ans ^= 1;
}
tree[x].out ^= 1;
cout << ans << endl;
}
}

signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
int t = 1; // cin >> t;
while(t--) solve();
return 0;
}
赞(0)
未经允许不得转载:上海聚慕医疗器械有限公司 » PLCT检查是什么[LCT刷题][树链信息维护] P4332 [SHOI2014]三叉神经树

登录

找回密码

注册