http://www.lydsy.com/JudgeOnline/problem.php?id=1180

今天状态怎么这么不好。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

又是调了好久。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

我竟然忘记更改值那里要先splay后再更改,而且还要pushup先!!!!!

QAQ

太弱了。。

记住!!!更改信息一定要先变成了根再修改,而且还要pushup!

(蒟蒻问了下神犇,总算弄懂了:“原树里面的父亲 在splay中可以是儿子”,所以在更新了父亲的点时,由于在splay中是儿子,所以没更新到在原树中是儿子的点。因此就错了。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } struct node* null;
struct node {
node *f, *c[2];
int w, s; bool rev;
node(int _k=0) { w=s=_k; f=c[0]=c[1]=null; rev=0; }
void setc(node *x, bool d) { c[d]=x; x->f=this; }
bool check() { return f==null || (f->c[0]!=this && f->c[1]!=this); }
bool d() { return f->c[1]==this; }
void pushup() { s=w+c[0]->s+c[1]->s; }
void upd() { if(this==null) return; rev=!rev; swap(c[0], c[1]); }
void pushdown() {
if(rev) {
rev=0;
c[0]->upd();
c[1]->upd();
}
}
};
void rot(node *x) {
node *f=x->f;
f->pushdown(); x->pushdown(); bool d=x->d();
if(f->check()) x->f=f->f;
else f->f->setc(x, f->d());
f->setc(x->c[!d], d);
x->setc(f, !d);
f->pushup();
}
void fix(node *x) { if(!x->check()) fix(x->f); x->pushdown(); }
void splay(node *x) {
fix(x);
while(!x->check())
if(x->f->check()) rot(x);
else x->d()==x->f->d()?(rot(x->f), rot(x)):(rot(x), rot(x));
x->pushup();
}
node* access(node *x) {
node *y=null;
for(; x!=null; y=x, x=x->f) splay(x), x->c[1]=y;
return y;
}
node* findroot(node *x) {
access(x); splay(x);
while(x->c[0]!=null) x=x->c[0];
return x;
}
void mkroot(node *x) { access(x)->upd(); splay(x); }
void link(node *x, node *y) { mkroot(x); x->f=y; } const int N=30005;
node *root[N];
int n;
int main() {
null=new node; null->f=null->c[0]=null->c[1]=null;
read(n);
for1(i, 1, n) root[i]=new node(getint());
int m=getint();
while(m--) {
char c=getchar(); while(c<'a'||c>'z') c=getchar();
int a=getint(), b=getint();
if(c=='b') {
if(findroot(root[a])==findroot(root[b])) puts("no");
else { puts("yes"); link(root[a], root[b]); };
}
else if(c=='p') { mkroot(root[a]); root[a]->w=b; root[a]->pushup(); }
else {
if(findroot(root[a])!=findroot(root[b])) { puts("impossible"); continue; }
mkroot(root[a]); access(root[b]); splay(root[b]);
printf("%d\n", root[b]->s);
}
}
return 0;
}

  


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

【BZOJ】1180: [CROATIAN2009]OTOCI & 2843: 极地旅行社(lct)的更多相关文章

  1. 【BZOJ1180】: [CROATIAN2009]OTOCI & 2843: 极地旅行社 LCT

    竟然卡了我....忘记在push_down先下传父亲的信息了....还有splay里for():卡了我10min,但是双倍经验还是挺爽的,什么都不用改. 感觉做的全是模板题,太水啦,不能这么水了... ...

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

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

  3. BZOJ 1180: [CROATIAN2009]OTOCI [LCT]

    1180: [CROATIAN2009]OTOCI Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 961  Solved: 594[Submit][S ...

  4. BZOJ 1180: [CROATIAN2009]OTOCI

    1180: [CROATIAN2009]OTOCI Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 989  Solved: 611[Submit][S ...

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

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

  6. bzoj 1180: [CROATIAN2009]OTOCI【LCT】

    一道几乎是板子的LCT,但是沉迷数学很久时候突然1A了这道题还是挺开心的 #include<iostream> #include<cstdio> using namespace ...

  7. 【刷题】BZOJ 1180 [CROATIAN2009]OTOCI

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

  8. 1180: [CROATIAN2009]OTOCI(LCT)

    1180: [CROATIAN2009]OTOCI Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 1200  Solved: 747[Submit][ ...

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

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

随机推荐

  1. RouterOS DNS劫持 -- A记录

    通常我们使用RouterOS的DNS主要是用于实现DNS缓存功能,即由RouterOS实现DNS服务器解析功能,除了这个功能,RouterOS可以实现对内网域名解析劫持,即实现路由网关的A记录查询. ...

  2. python4delphi import lxml pandas 出错的小结

    环境: 1.win10 64位 2.delphi xe8 3.python2.7 4.python4delphi  (svn 2015-03-21 发布的83版本号) 5.lxml 3.4.4(通过p ...

  3. Python配合BeautifulSoup读取网络图片并保存在本地

    本例为Python配合BeautifulSoup读取网络图片,并保存在本地. BeautifulSoup可代替正则表达式,更好地解析Html文本,获取其中的指定内容,如Tag.Property等 # ...

  4. Scrapy and Selenium

    How to scrapy js? scrapy结合webkit抓取js生成的页面 http://www.cnblogs.com/Safe3/archive/2011/10/19/2217965.ht ...

  5. IIS安装时,添加/编辑应用程序扩展名映射 确定按钮不可用。

    原因是:执行文件的路径太长,需要激活按钮. 方法一:选择较短路径的执行文件,先激活按钮. 方法二:点击该路径,就可以激活确认按钮了.

  6. Linux系统Shutdown命令定时关机详解

    转自:http://www.bootf.com/490.html Linux系统下的shutdown命令用于安全的关闭/重启计算机,它不仅可以方便的实现定时关机,还可以由用户决定关机时的相关参数.在执 ...

  7. Cocos2d-JS游戏导演

    什么是游戏的导演 具体来说,Cocos2d-JS中的导演是一个对象,它负责设置游戏的运行环境,控制游戏的住循环并且管理场景和场景的切换. 导演的任务 Cocos2d-JS中导演对象名为:cc.dire ...

  8. 分页管理的JSTL实现

    userMgr.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

  9. 神经网络(luogu 1038 答案错误,出题人语体教)

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  10. WebService之CXF框架

    本文主要包括以下内容 ant工具的使用 利用cxf实现webservice cxf与spring整合 ajax访问webservice ant 工具 1.为什么要用到ant这个工具呢? Ant做为一种 ...