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 【block类型全方位详解】

    ------------------------------------------- block变量的概念 #import <Foundation/Foundation.h> int m ...

  2. C语言知识总结(2)

    选择结构-if if(表达式) {} {}为作用域 多重if-else  例如: #include <stdio.h> int main(){ ; ){ printf("没有购物 ...

  3. 如何让R代码按计划执行

    应用场景:你编写了R代码,每天对提交的数据进行分析,你希望它你吃饭的时候执行完毕,生成图表. 那么你需要安装taskscheduleR的包. 怎么操作,看帮助呗.

  4. (转)MongoDB 3.0 WT引擎参考配置文件

    mongodb 3.0 改变很多,从2.6版本升级到3.0要关注的细节很多,如权限等等.3.0在数据存储引擎上更换成了wiredTiger,在数据压缩方面很有效,解决大数据量问题的情况下,磁盘不够用的 ...

  5. Java 字符流实现文件读写操作(FileReader-FileWriter)

    Java 字符流实现文件读写操作(FileReader-FileWriter) 备注:字符流效率高,但是没有字节流底层 字节流地址:http://pengyan5945.iteye.com/blog/ ...

  6. Source Insight建工程之Kernel

     不管你是从事于Linux内核工作还是出于兴趣爱好,Linux内核源码都是非常好的学习资源.意味着就要经常的和内核源码大交道,那么软件工具就是少不了的.在Windows系统上确实有着许多好用的软件 ...

  7. Apache+lvs高可用+keepalive(主从+双主模型)

    Apache+lvs高可用+keepalive(主从+双主模型)     keepalive实验准备环境: httpd-2.2.15-39.el6.centos.x86_64 keepalived-1 ...

  8. Mysql支持中文全文检索的插件mysqlcft-应用中的问题

    MySQL目前版本的全文检索没有对中文很好的支持,但可以通过安装mysqlcft插件来实现,具体的安装使用方法:http://blog.s135.com/post/356/ mysqlcft的官方网站 ...

  9. windows不能在本地计算机启动apache

    今天,配置eclipse PHP studio 3.0的时候更改了apache http server 中的httpd.conf文件: 将DocumentRoot 的路径设错了,为一个不存在目录 .更 ...

  10. jeecms子栏目或者文章页导航父栏目选中解决方法

    jeecms在子栏目或者文章页导航父栏目选中,看例子 <div class="nav"> <ul> [@cms_channel_list ] <li ...