hahaha
Posted thx666
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hahaha相关的知识,希望对你有一定的参考价值。
#include<cstdio> #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<string> #include<iostream> #include<algorithm> #include<set> #include<map> #include<queue> #include<stack> #include<vector> #define enter puts("") using namespace std; typedef long long ll; const int maxn = 5e4 + 5; int head[maxn], tot, cnt, n, m, fa[maxn];//cnt表示节点个数 ,fa[]用于查找树根 struct E { int to, next, val; }ed[maxn];//存储输入的关系图 struct dfsid { int lef, rig; }bc[maxn];//存储dfs序,bc[i].lef表示i第一次出现的序号, bc[i].rig表示i第二次出现的序号 struct Tree { int data, upd; }lj[maxn << 2];//存储线段树,data表示节点值,upd表示区间更新的lazy标记 int read() { int ans = 0, op = 1; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘) { if(ch == ‘-‘) op = 0; ch = getchar(); } while(ch >= ‘0‘ && ch <= ‘9‘) { ans *= 10; ans += ch - ‘0‘; ch = getchar(); } return op ? ans : -ans; } void write(int x) { if(x < 0) { x = -x; putchar(‘-‘); } if(x >= 10) write(x / 10); putchar(‘0‘ + x % 10); } void init() { memset(head, -1, sizeof(head)); memset(fa, -1, sizeof(fa)); memset(lj, -1, sizeof(Tree) * (maxn << 2)); tot = 0, cnt = 0; } void addedge(int u, int v, int w) { ed[tot].to = v; ed[tot].next = head[u]; ed[tot].val = w; head[u] = tot++; } void dfs(int u) { cnt++; bc[u].lef = cnt; for(int i = head[u];i ^ -1;i = ed[i].next) dfs(ed[i].to); bc[u].rig = cnt; } void build(int l, int r, int now) { lj[now].upd = -1; if(l == r) return (void)(lj[now].data = -1); int mid = (l + r) >> 1; build(l, mid, now << 1); build(mid + 1, r, now << 1 | 1); } void mark_change(int l, int r, int now, int xg) { lj[now].data = xg; lj[now].upd = xg; } void pushdown(int l, int r, int now) { if(lj[now].upd == -1) return ; int mid = (l + r) >> 1; mark_change(l, mid, now << 1, lj[now].upd); mark_change(mid + 1, r, now << 1 | 1, lj[now].upd); lj[now].upd = -1; } void update(int l, int r, int now, int ql, int qr, int xg) { if(ql <= l && qr >= r) return mark_change(l, r, now, xg); int mid = (l + r) >> 1; pushdown(l, r, now); if(ql <= mid) update(l, mid, now << 1, ql, qr, xg); if(qr > mid) update(mid + 1, r, now << 1 | 1, ql, qr, xg); } int ask(int l, int r, int now, int id) { if(l == r) return lj[now].data; int mid = (l + r) >> 1; if(id <= mid) return ask(l, mid, now << 1, id); else return ask(mid + 1, r, now << 1 | 1, id); } int main() { int T; T = read(); for(int t = 1; t <= T; t++) { printf("Case #%d: ", t); init(); n = read(); for(int i = 2; i <= n; i++) { int u, v; u = read(), v = read(); addedge(v, u, 1); fa[u]++; } for(int i = 1; i <= n; i++) { //从原树根深搜 if(fa[i] == 0) { dfs(i); break; } } build(1, cnt, 1); m = read(); while(m--) { char ch[3]; scanf("%s", ch); if(ch[0] == ‘C‘) { int x; x = read(); write(ask(1, cnt, 1, bc[x].lef)); enter; } else { int x, y; x = read(), y = read(); update(1, cnt, 1, bc[x].lef, bc[x].rig, y); } } } return 0; }
以上是关于hahaha的主要内容,如果未能解决你的问题,请参考以下文章