【BZOJ】【2157】旅游
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】旅游的更多相关文章
- BZOJ 2157: 旅游( 树链剖分 )
树链剖分.. 样例太大了根本没法调...顺便把数据生成器放上来 -------------------------------------------------------------------- ...
- bzoj 2157: 旅游 (LCT 边权)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2157 题面; 2157: 旅游 Time Limit: 10 Sec Memory Lim ...
- BZOJ 2157: 旅游
2157: 旅游 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1347 Solved: 619[Submit][Status][Discuss] ...
- 【刷题】BZOJ 2157 旅游
Description Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间 ...
- BZOJ 2157 旅游(动态树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2157 [题目大意] 支持修改边,链上查询最大值最小值总和,以及链上求相反数 [题解] ...
- BZOJ 2157 旅游(树链剖分+线段树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2157 [题目大意] 支持修改边,链上查询最大值最小值总和,以及链上求相反数 [题解] ...
- 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 ...
- bzoj 2157: 旅游【树链剖分+线段树】
裸的树链剖分+线段树 但是要注意一个地方--我WA了好几次才发现取完相反数之后max值和min值是要交换的-- #include<iostream> #include<cstdio& ...
- BZOJ 2157: 旅游 (树链剖分+线段树)
树链剖分后线段树维护区间最大最小值与和. 支持单点修改与区间取反. 直接写个区间取反标记就行了.线段树板题.(200行6000B+ 1A警告) #include <cstdio> #inc ...
- BZOJ 2157: 旅游 (结构体存变量)
用结构体存变量好像确实能提高运行速度,以后就这么写数据结构了 Code: #include <cstdio> #include <algorithm> #include < ...
随机推荐
- cocos2dx-lua之断点调试支持
cocos2dx 3.2版对cocos code ide支持已经相当棒了,不过话说,编辑器用起来感觉没有sublime顺手 支持cocos code ide已经支持创建lua项目了,可是默认创建的项目 ...
- windows下部署 ISCSI存储
Write bt xiaoyang 配置篇 这里使用的软件为iscsiTargetqfe 1. 首先安装软件,可在微软官网下载 2. 然后找到安装程序 3. 完成安装后打 ...
- Linux下DNS服务器的基本搭建
技术交流群:286866978 安装与配置 1. 装载光驱 2. 卸载光驱 3. 将安装包放在合适的文件夹并解压(有的更换光盘需要重新装载) 4. 安装 5. 重定向配置文件 6. 配置named.c ...
- Oracle在所有内容前追加一些内容的方法
参照下面的sql语句. SQL> SELECT * FROM UserInfo; NAME CHINESE -------------------- ...
- iOS - 移动设备防丢失App
一.原理 二.数据获取 三.报警
- TreeView控件的CheckBox级联选中或取消
背景: 在一个项目开发中遇到这样的要求:当选中树中一个节点时,需要同时选中其父节点,直至根节点.在取消一个节点的选中时,需要将其所有子节点取消选中,直至叶子节点.由于项目用户体验暂时可以不用考虑,直接 ...
- Requirejs学习笔记(一)
中文api 和 英文api网上都有的我就不翻译了,我的学习方法是先看英文api,然后看不懂的就比对中文api看一遍. requirejs可以帮助js代码模块化开发,模块化意味了解决了代码凌乱的问题,方 ...
- Fragstats软件使用及其景观生态学意义
[转]Fragstats软件使用及其景观生态学意义 原文地址:http://blog.163.com/shuailai@126/blog/static/13238040820104152513 ...
- 济南学习 Day 4 T1 am
完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...
- gcc常用命令介绍
GCC 全称是 GNU C Compiler,是gnu中最流行的c & c++编译器,下面我们看一下一些主要的参数使用方法. 对于一个源文件可以直接生成可执行文件 gcc test.c 默认生 ...