LCT

  直到动手写拆边为点的时候才发现根本不会写……去orz了一下Hzwer(话说这题应该也用不着LCT吧……下次再换种姿势写一遍好了)

 /**************************************************************
Problem: 2157
User: Tunix
Language: C++
Result: Accepted
Time:668 ms
Memory:2600 kb
****************************************************************/ //BZOJ 2157
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*=sign;
}
/******************tamplate*********************/
const int N=,INF=~0u>>;
int n,m,cnt;
int ed[N];
int c[N][],fa[N],v[N],sum[N],mn[N],mx[N];
bool rev[N],Not[N];
#define L c[x][0]
#define R c[x][1]
bool not_root(int x){
return c[fa[x]][]==x || c[fa[x]][]==x;
}
void rever(int x){
sum[x]=-sum[x]; v[x]=-v[x];
swap(mn[x],mx[x]);
mn[x]=-mn[x];mx[x]=-mx[x];
Not[x]^=;
}
void Push_up(int x){
mx[x]=max(mx[L],mx[R]);
mn[x]=min(mn[L],mn[R]);
if (x>n){
mx[x]=max(mx[x],v[x]);
mn[x]=min(mn[x],v[x]);
}
sum[x]=sum[L]+sum[R]+v[x];
}
void Push_down(int x){
if (Not[x]){
Not[x]^=;
if (L) rever(L);
if (R) rever(R);
}
if (rev[x]){
rev[x]^=; rev[L]^=; rev[R]^=;
swap(L,R);
}
}
void rotate(int x){
int y=fa[x],z=fa[y],l=c[y][]==x,r=l^;
if (not_root(y)) c[z][c[z][]==y]=x;
fa[x]=z; fa[y]=x; fa[c[x][r]]=y;
c[y][l]=c[x][r]; c[x][r]=y;
Push_up(y);
}
void preview(int x){
if (not_root(x)) preview(fa[x]);
Push_down(x);
}
void splay(int x){
int y;
for(preview(x);not_root(x);rotate(x))
not_root(y=fa[x]) ? rotate(c[y][]==x^c[fa[y]][]==y ? x : y),:;
Push_up(x);
}
void access(int x,int las=){
for(;x;splay(x),c[x][]=las,las=x,x=fa[x]);
}
void makeroot(int x){
access(x),splay(x),rev[x]^=;
}
void link(int x,int y){
makeroot(x),fa[x]=y;
}
void query(int x,int y){
makeroot(x),access(y),splay(y);
}
int main(){
n=getint();
F(i,,n) mn[i]=INF,mx[i]=-INF;
int id=n;
F(i,,n-){
int x=getint()+,y=getint()+,w=getint();
ed[i]=++id;
link(x,id); link(y,id);
v[id]=sum[id]=mx[id]=mn[id]=w;
}
m=getint();
char cmd[]; int x,y;
F(i,,m){
scanf("%s",cmd);
x=getint(); y=getint();
if (cmd[]=='C'){
splay(ed[x]),v[ed[x]]=y,Push_up(ed[x]);
}
else if(cmd[]=='N')
query(x+,y+),rever(y+);
else if(cmd[]=='S')
query(x+,y+),printf("%d\n",sum[y+]);
else if(cmd[]=='A')
query(x+,y+),printf("%d\n",mx[y+]);
else query(x+,y+),printf("%d\n",mn[y+]);
}
return ;
}

【BZOJ】【2157】旅游的更多相关文章

  1. BZOJ 2157: 旅游( 树链剖分 )

    树链剖分.. 样例太大了根本没法调...顺便把数据生成器放上来 -------------------------------------------------------------------- ...

  2. bzoj 2157: 旅游 (LCT 边权)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2157 题面; 2157: 旅游 Time Limit: 10 Sec  Memory Lim ...

  3. BZOJ 2157: 旅游

    2157: 旅游 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1347  Solved: 619[Submit][Status][Discuss] ...

  4. 【刷题】BZOJ 2157 旅游

    Description Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间 ...

  5. BZOJ 2157 旅游(动态树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2157 [题目大意] 支持修改边,链上查询最大值最小值总和,以及链上求相反数 [题解] ...

  6. BZOJ 2157 旅游(树链剖分+线段树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2157 [题目大意] 支持修改边,链上查询最大值最小值总和,以及链上求相反数 [题解] ...

  7. BZOJ 2157: 旅游 (2017.7.21 6:30-2017.7.21 15:38 今日第一题。。)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1754  Solved: 765 Description Ray 乐忠于旅游,这次他来到了T 城.T ...

  8. bzoj 2157: 旅游【树链剖分+线段树】

    裸的树链剖分+线段树 但是要注意一个地方--我WA了好几次才发现取完相反数之后max值和min值是要交换的-- #include<iostream> #include<cstdio& ...

  9. BZOJ 2157: 旅游 (树链剖分+线段树)

    树链剖分后线段树维护区间最大最小值与和. 支持单点修改与区间取反. 直接写个区间取反标记就行了.线段树板题.(200行6000B+ 1A警告) #include <cstdio> #inc ...

  10. BZOJ 2157: 旅游 (结构体存变量)

    用结构体存变量好像确实能提高运行速度,以后就这么写数据结构了 Code: #include <cstdio> #include <algorithm> #include < ...

随机推荐

  1. C#实现自定义事件,用于监视变量变化

    很多时候我们需要程序具有一种功能,就是当满足某一条件时触发某个动作,使用C#的事件机制就可以达到这个目的下面的例子是一个很好的演示. 这段代码实现了对一个变量的监视,一旦变量发生改变,就触发动作 定义 ...

  2. iOS - 苹果健康架构 & 基于HealthKit的健康数据的编辑

    最近公司需求,研究了一周之久的苹果健康架构,内容包括:资料调研.报告与HealthKit.framework - API,这一研习还在持续进行中.至此,主要认识到了2点:对苹果健康健康架构设计与实现原 ...

  3. UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]

    ////  ViewController.h//  UIAlertViewAndUIActionSheet////  Created by hehe on 15/9/21.//  Copyright ...

  4. 前台JS(Jquery)调用后台方法 无刷新级联菜单示例

    前台用AJAX直接调用后台方法,老有人发帖提问,没事做个示例 下面是做的一个前台用JQUERY,AJAX调用后台方法做的无刷新级联菜单 http://www.dtan.so CasMenu.aspx页 ...

  5. IE8 textarea 滚动条定位不准解决方法

    工作中遇到一个bug: IE8 下textarea 如果带滚动条(height:100px;overflow:scroll-y;),内容高度超过可视区域之后,输入文字,滚动条位置会乱跳. 开始以为是j ...

  6. (转)一网打尽当下NoSQL类型、适用场景及使用公司

    摘要:对比传统关系型数据库,NoSQL有着更为复杂的分类——键值.面向文档.列存储以及图数据库.这里就带你一览NoSQL各种类型的适用场景及一些知名公司的方案选择. 在过去几年,关系型数据库一直是数据 ...

  7. 链表的创建、测长、排序、插入、逆序的实现(C语言)

    #include <stdio.h> #define END_elem 0 struct node { int date; struct node * next; }; //链表创建 no ...

  8. C++ Stacks(堆栈)

    C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. 操作 比较和分配堆栈 empty() 堆栈为空则返回真 pop() ...

  9. Linux 软中断

    本文转载自: http://blog.chinaunix.net/uid-9620812-id-3833377.html,如有需要,请移步访问. Technorati 标签: Linux 软中断 -- ...

  10. Ubuntu搜狗输入法的使用

    下载搜狗拼音输入法安装包 删除ibus,确认没有以ibus开头的包存在 sudo dpkg -P ibus ibus-gtk ibus-gtk3 ibus-pinyin ibus-pinyin-db- ...