竟然卡了我。。。。忘记在push_down先下传父亲的信息了。。。。还有splay里for();卡了我10min,但是双倍经验还是挺爽的,什么都不用改。

感觉做的全是模板题,太水啦,不能这么水了。。。

不过模板都敲不对,啥也做不好!!!

 #include <iostream>
#include <cstdio>
#define N 300030
using namespace std;
int n,m;
struct node
{
node *fa,*ch[];
int data,sum;
bool rev;
node(int x);
bool chr() {return this==fa->ch[];}
bool isrt() {return this!=fa->ch[] && this!=fa->ch[];}
void push_up() {sum=ch[]->sum+ch[]->sum+data;}
void setc(node *x,int t) {this->ch[t]=x; x->fa=this;}
void push_down()
{
if (!isrt()) fa->push_down();
if (rev)
{
ch[]->rev^=;
ch[]->rev^=;
swap(ch[],ch[]);
rev=;
}
}
}*null=new node(),*lct[N];
node::node (int x) {fa=ch[]=ch[]=null; data=sum=x; rev=;}
inline int read()
{
char c;
int ans=,f=;
while (!isdigit(c=getchar())) {if (c=='-') f=-;}
ans=c-'';
while (isdigit(c=getchar())) ans=ans*+c-'';
return ans*f;
}
namespace LCT
{
void rotate(node *x)
{
node *r=x->fa;
if (x==null || r==null) return;
int t=x->chr();
//x->push_down();r->push_down();
if (r->isrt()) x->fa=r->fa;
else r->fa->setc(x,r->chr());
r->setc(x->ch[t^],t);
x->setc(r,!t);
x->push_up(); r->push_up();
}
void Splay(node *x)
{
x->push_down();
for (;!x->isrt();rotate(x))
if (!x->fa->isrt())
if (x->chr()==x->fa->chr()) rotate(x->fa);
else rotate(x);
x->push_up();
}
void Access(node *x)
{
node *r=null;
for (;x!=null;r=x,x=x->fa)
{
Splay(x);
x->ch[]=r;
}
}
void MakeRoot(node *x)
{
Access(x);
Splay(x);
x->rev^=;
}
void Link(node *x,node *y)
{
MakeRoot(x);
x->fa=y;
}
void Cut(node *x,node *y)
{
MakeRoot(x);
Access(y); Splay(y);
y->ch[]->fa=null; y->ch[]=null;
}
node *Find(node *x)
{
Access(x); Splay(x);
while (x->ch[]!=null) x=x->ch[];
return x;
}
void Change(node *x,int v)
{
x->push_down();
Splay(x);
x->data=v;
x->push_up();
}
int Query(node *x,node *y)
{
MakeRoot(x);
Access(y); Splay(y);
return y->sum;
}
}
using namespace LCT;
int main()
{
char s[];
int x,y;
n=read();
for (int i=;i<=n;i++) x=read(),lct[i]=new node(x);
m=read();
for (int i=;i<=m;i++)
{
scanf("%s",s); x=read(); y=read();
if (s[]=='b') if (Find(lct[x])!=Find(lct[y])) printf("yes\n"),Link(lct[x],lct[y]);
else printf("no\n");
if (s[]=='p') Change(lct[x],y);
if (s[]=='e') if (Find(lct[x])==Find(lct[y])) printf("%d\n",Query(lct[x],lct[y]));
else printf("impossible\n");
}
return ;
}

Description

给出n个结点以及每个点初始时对应的权值wi。起始时点与点之间没有连边。有3类操作: 1、bridge A B:询问结点A与结点B是否连通。如果是则输出“no”。否则输出“yes”,并且在结点A和结点B之间连一条无向边。 2、penguins A X:将结点A对应的权值wA修改为X。 3、excursion A B:如果结点A和结点B不连通,则输出“impossible”。否则输出结点A到结点B的路径上的点对应的权值的和。给出q个操作,要求在线处理所有操作。数据范围:1<=n<=30000, 1<=q<=300000, 0<=wi<=1000。

Input

第一行包含一个整数n(1<=n<=30000),表示节点的数目。第二行包含n个整数,第i个整数表示第i个节点初始时对应的权值。第三行包含一个整数q(1<=n<=300000),表示操作的数目。以下q行,每行包含一个操作,操作的类别见题目描述。任意时刻每个节点对应的权值都是1到1000的整数。

Output

输出所有bridge操作和excursion操作对应的输出,每个一行。

Sample Input

5
4 2 4 5 6
10
excursion 1 1
excursion 1 2
bridge 1 2
excursion 1 2
bridge 3 4
bridge 3 5
excursion 4 5
bridge 1 3
excursion 2 4
excursion 2 5

Sample Output

4
impossible
yes
6
yes
yes
15
yes
15
16

HINT

 

Source

 

【BZOJ1180】: [CROATIAN2009]OTOCI & 2843: 极地旅行社 LCT的更多相关文章

  1. 【BZOJ】1180: [CROATIAN2009]OTOCI & 2843: 极地旅行社(lct)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1180 今天状态怎么这么不好..................................... ...

  2. BZOJ 2843: 极地旅行社( LCT )

    LCT.. ------------------------------------------------------------------------ #include<cstdio> ...

  3. BZOJ 2843: 极地旅行社 lct splay

    http://www.lydsy.com/JudgeOnline/problem.php?id=2843 https://blog.csdn.net/clove_unique/article/deta ...

  4. [bzoj2843&&bzoj1180]极地旅行社 (lct)

    双倍经验双倍的幸福... 所以另一道是300大洋的世界T_T...虽然题目是一样的,不过2843数据范围小了一点... 都是lct基本操作 #include<cstdio> #includ ...

  5. BZOJ1180 [CROATIAN2009]OTOCI LCT

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1180 本题和BZOJ2843一样. BZOJ2843 极地旅行社 LCT 题意概括 有n座岛 每座 ...

  6. BZOJ2843极地旅行社&BZOJ1180[CROATIAN2009]OTOCI——LCT

    题目描述 给出n个结点以及每个点初始时对应的权值wi.起始时点与点之间没有连边.有3类操作:  1.bridge A B:询问结点A与结点B是否连通. 如果是则输出“no”.否则输出“yes”,并且在 ...

  7. bzoj 2843 极地旅行社(LCT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2843 [题意] 给定一个森林,要求提供连边,修改点值,查询路径和的操作. [思路] L ...

  8. BZOJ1180 [CROATIAN2009]OTOCI 【LCT】

    题目 给出n个结点以及每个点初始时对应的权值wi.起始时点与点之间没有连边.有3类操作: 1.bridge A B:询问结点A与结点B是否连通.如果是则输出"no".否则输出&qu ...

  9. BZOJ 1180 [CROATIAN 2009]OTOCI // BZOJ 2843 极地旅行社 // Luogu P4321 [COCI 2009] OTOCI / 极地旅行社 (LCA板题)

    emmm-标题卡着长度上限- LCT板题-(ε=ε=ε=┏(゜ロ゜;)┛) CODE #include <cctype> #include <cmath> #include & ...

随机推荐

  1. centos 7.0 编译安装php 5.6.7

    编译安装php参考资料 MySQL PHP API http://dev.mysql.com/doc/apis-php/en/index.html nginx + php +mysql 最简单安装 官 ...

  2. 【09-23】js原型继承学习笔记

    js原型继承学习笔记 function funcA(){ this.a="prototype a"; } var b=new funcA(); b.a="object a ...

  3. codevs2777 栅栏的木料

    题目描述 Description 农民John准备建一个栅栏来围住他的牧场.他已经确定了栅栏的形状,但是他在木料方面有些问题.当地的杂货储存商扔给John一些木板,而John必须从这些木板中找出尽可能 ...

  4. scp命令详解

    \ svn 删除所有的 .svn文件 find . -name .svn -type d -exec rm -fr {} \; linux之cp/scp命令+scp命令详解   名称:cp 使用权限: ...

  5. UVALive 3027 Corporative Network

    ---恢复内容开始--- Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

  6. PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?

    1."自定义"常用快捷键(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> ...

  7. eclipse for php现有项目不能导入问题

    1.少了.project文件 解决办法:创建一个新项目,然后将新项目文件夹下的.project文件复制到将要导入的文件夹中.

  8. Git 常用命令合集

    $ git init          建立git仓库(一般都是在github上新建好,直接克隆到本地) $ git clone **.git       克隆git仓库 $ git add -A   ...

  9. C#获取命令行输出内容的方法

    获取命令行输出内容的方式有传统和异步两种方式. 传统方式: public static void RunExe(string exePath, string arguments, out string ...

  10. Python基础二

    1.for循环后接else __author__ = "zhou" age_of_oldboy = 56 for i in range(3): guess_age = int(in ...