zoukankan      html  css  js  c++  java
  • BZOJ-2049 [SDOI2008]洞穴勘测

    LCT模版题。。。。

    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <cctype>
    #include <cmath>
    #define rep(i, l, r) for(int i=l; i<=r; i++)
    #define clr(x, c) memset(x, c, sizeof(x))
    #define travel(x) for(edge *p=fir[x]; p; p=p->n)
    #define l(x) c[x][0]
    #define r(x) c[x][1]
    #define f(x) Father[x]
    #define h(x) Head[x]
    #define maxn 10009
    #define inf 0x7fffffff
    using namespace std;
    inline int read()
    {
    	int x=0, f=1; char ch=getchar();
    	while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    	while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
    	return x*f;
    }
    int n, c[maxn][2], Head[maxn], Father[maxn];
    bool rev[maxn];
    
    inline void pushdown(int x)
    {
    	rev[x]^=1, rev[l(x)]^=1, rev[r(x)]^=1;
    	swap(l(l(x)), r(l(x))), swap(l(r(x)), r(r(x)));
    }
    inline void rotate(int x)
    {
    	int y=f(x), z=f(y), l=(c[y][1]==x), r=l^1;
    	if (z) c[z][c[z][1]==y]=x;
    	f(c[x][r])=y, f(y)=x, f(x)=z;
    	c[y][l]=c[x][r]; c[x][r]=y;
    }
    inline void Splay(int x)
    {
    	if (!x) return; if (rev[x]) pushdown(x); int y;
    	while (f(x)) 
    	{
    		if (rev[y=f(x)]) pushdown(y), pushdown(x);
    		if (!f(y)) h(x)=h(y), h(y)=0;
    		rotate(x);
    	}
    }
    inline void Acc(int x)
    {
    	int cmp=x, y; Splay(x); 
    	f(r(x))=0, h(r(x))=x, r(x)=0;
    	while (h(x)) 
    		Splay(y=h(x)), f(r(y))=0, h(r(y))=y, r(y)=x, f(x)=y, h(x)=0, x=y;
    	Splay(cmp);
    }
    inline void Eve(int x){Acc(x); rev[x]^=1; swap(l(x), r(x));}
    inline int Top(int x){Acc(x); int now=x; while (l(now)) now=l(now); return now;}
    inline void Build(){rep(i, 1, n) l(i)=r(i)=h(i)=f(i)=0;}
    inline void Connect(int x, int y){Eve(x); Eve(y); Splay(y); h(x)=y;}
    inline void Destroy(int x, int y){Eve(x); Acc(y); f(x)=l(y)=0;}
    inline void Query(int x, int y){if (Top(x)==Top(y)) puts("Yes"); else puts("No");}
    int main()
    {
    	n=read(); int m=read(); Build();
    	rep(i, 1, m)
    	{
    		char ch[5]; scanf("%s", ch); int x=read(), y=read();
    		if (ch[0]=='C') Connect(x, y); else if (ch[0]=='D') Destroy(x, y); else Query(x, y);
    	}
    	return 0;
    }
  • 相关阅读:
    Oracle中有大量的sniped会话
    Error 1130: Host '127.0.0.1' is not allowed to connect to this MySQL server
    汉字转换为拼音以及缩写(javascript)
    高效率随机删除数据(不重复)
    vs2010 舒服背景 优雅字体 配置
    mvc中的ViewData用到webfrom中去
    jquery ajax return值 没有返回 的解决方法
    zShowBox (图片放大展示jquery版 兼容性好)
    动感效果的TAB选项卡 jquery 插件
    loading 加载提示······
  • 原文地址:https://www.cnblogs.com/NanoApe/p/4479770.html
Copyright © 2011-2022 走看看