https://www.luogu.org/problemnew/show/P3250

树链剖分 + 线段树 + 优先队列
要求未被影响的请求中最大的
所以每次将每条路径在整棵树上的补集的每个节点的优先队列加入该路径的权值

mid 敲错调了一上午

气炸。。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector> using namespace std;
const int N = 1e5 + ; #define yxy getchar()
#define lson jd << 1
#define rson jd << 1 | 1 #define RR freopen("gg.in", "r", stdin) int n, Ty, Tim, how, ans;
int fa[N], topp[N], deep[N], size[N], son[N], tree[N];
priority_queue <int> Q1[N << ], Q2[N << ];
vector <int> vec[N << ];
struct Node{int up, down;} D[N];
struct Node2{int l, r, val;} Ask[N << ]; inline int read() {
int x = ; char c = yxy;
while(c < '' || c > '') c = yxy;
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x;
} void Dfs_son(int u, int f_, int dep) {
fa[u] = f_;
deep[u] = dep;
size[u] = ;
int siz_ = vec[u].size();
for(int i = ; i < siz_; i ++) {
int v = vec[u][i];
if(v != f_) {
Dfs_son(v, u, dep + );
size[u] += size[v];
if(size[v] > size[son[u]]) son[u] = v;
}
}
} void Dfs_un(int u, int tp) {
topp[u] = tp;
tree[u] = ++ Tim;
if(!son[u]) return ;
Dfs_un(son[u], tp);
int siz_ = vec[u].size();
for(int i = ; i < siz_; i ++) {
int v = vec[u][i];
if(v != fa[u] && v != son[u]) Dfs_un(v, v);
}
} inline bool cmp(Node a, Node b) {return a.up < b.up;} void Sec_G(int l, int r, int jd, int x, int y, int yj) {
if(x <= l && r <= y) {
if(how == ) Q1[jd].push(yj);
else Q2[jd].push(yj);
return ;
}
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y, yj);
if(y > mid) Sec_G(mid + , r, rson, x, y, yj);
} inline void Sec_G_imp(int x, int y, int val) {
int tp1 = topp[x], tp2 = topp[y], js();
while(tp1 != tp2) {
if(deep[tp1] < deep[tp2]) swap(x, y), swap(tp1, tp2);
D[++ js].up = tree[tp1];
D[js].down = tree[x];
x = fa[tp1];
tp1 = topp[x];
}
if(deep[x] < deep[y]) swap(x, y);
D[++ js].up = tree[y]; D[js].down = tree[x];
sort(D + , D + js + , cmp);
int last = ;
for(int i = ; i <= js; i ++) {
int l_ = last + , r_ = D[i].up - ;
if(l_ <= r_) Sec_G(, n, , l_, r_, val);
last = D[i].down;
}
int l_ = last + , r_ = n;
if(l_ <= r_) Sec_G(, n, , l_, r_, val);
} int get_answer(int jd) {
int ret = -;
while(!Q2[jd].empty() && (Q1[jd].top() == Q2[jd].top())) Q1[jd].pop(), Q2[jd].pop();
if(Q1[jd].empty()) return -;
return Q1[jd].top();
} void Sec_A(int l, int r, int jd, int x) {
ans = max(ans, get_answer(jd));
if(l == r) return ;
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, lson, x);
else Sec_A(mid + , r, rson, x);
} int main() {
n = read();
Ty = read();
for(int i = ; i < n; i ++) {
int u = read(), v = read();
vec[u].push_back(v);
vec[v].push_back(u);
}
Dfs_son(, , );
Dfs_un(, );
for(int i = ; i <= Ty; i ++) {
int opt = read();
if(opt == ) { //添加
Ask[i].l = read(), Ask[i].r = read(), Ask[i].val = read();
how = ;
Sec_G_imp(Ask[i].l, Ask[i].r, Ask[i].val);
} else if(opt == ) { //删除
int x = read();
how = -;
Sec_G_imp(Ask[x].l, Ask[x].r, Ask[x].val);
} else { //查询
int x = read();
ans = -;
Sec_A(, n, , tree[x]);
cout << ans << endl;
}
}
return ;
}

[Luogu] 网络的更多相关文章

  1. [Luogu 2604] ZJOI2010 网络扩容

    [Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...

  2. luogu 1327 数列排序 & 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J题 循环节

    luogu 1327 数列排序 题意 给定一个数列\(\{an\}\),这个数列满足\(ai≠aj(i≠j)\),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? ...

  3. BZOJ 1834 Luogu P2604 [ZJOI2010]网络扩容 (最小费用最大流)

    题目连接: (luogu) https://www.luogu.org/problemnew/show/P2604 (bzoj) https://www.lydsy.com/JudgeOnline/p ...

  4. P3376 【模板】网络最大流(luogu)

    P3376 [模板]网络最大流(luogu) 最大流的dinic算法模板(采取了多种优化) 优化 时间 inline+当前弧+炸点+多路增广 174ms no 当前弧 175ms no 炸点 249 ...

  5. 【Luogu P3376】网络最大流

    Luogu P3376 最大流是网络流模型的一个基础问题. 网络流模型就是一种特殊的有向图. 概念: 源点:提供流的节点(入度为0),类比成为一个无限放水的水厂 汇点:接受流的节点(出度为0),类比成 ...

  6. LOJ #2547 Luogu P4517「JSOI2018」防御网络

    好像也没那么难写 LOJ #2547 Luogu P4517 题意 在一棵点仙人掌中等概率选择一个点集 求选出点集的斯坦纳树大小的期望 定义点仙人掌为不存在一个点在多个简单环中的连通图 斯坦纳树为在原 ...

  7. Luogu P2002 消息扩散&&P1262 间谍网络

    怕自己太久没写Tarjan了就会把这种神仙算法忘掉. 其实这种类型的图论题的套路还是比较简单且显然的. P2002 消息扩散 很显然的题目,因为在一个环(其实就是强连通分量)中的城市都只需要让其中一个 ...

  8. 【题解】Luogu P2604 [ZJOI2010]网络扩容

    原题传送门:P2604 [ZJOI2010]网络扩容 这题可以说是板题 给你一个图,先让你求最大流 再告诉你,每条边可以花费一些代价,使得流量加一 问至少花费多少代价才能使最大流达到k 解法十分简单 ...

  9. 【luogu P1262 间谍网络】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1262 注意: 1.缩点时计算出入度是在缩完点的图上用color计算.不要在原来的点上计算. 2.枚举出入度时 ...

随机推荐

  1. 【规律】Cunning Friends

    Cunning Friends 题目描述 Anthony and his friends Ben and Chris decided to play a game. They have N piles ...

  2. spring cloud 停止服务

    shutdown的默认url为host:port/shutdown,当需要停止服务时,向服务器post该请求即可,如:curl -X POST host:port/shutdown将得到形如{&quo ...

  3. Apache2.4+Tomcat7.0+php5.5整合配置详解

    在上一篇的基础上,继续添加php的配置 一.首先下载php5.5 首先下载php5.5,到官网下载http://www.php.net/downloads.php,参考http://www.cnblo ...

  4. Git 常用命令 MD

    | Markdown版本笔记 | 我的GitHub首页 | 我的博客 | 我的微信 | 我的邮箱 || :------------: | :------------: | :------------: ...

  5. 动手篇:简单的注册界面与防SQL注入(续)

    注册前先判断用户名是否已经存在,通过if (SqlHelper.Exists(strSql))查询判断是否已经存在.没存在则进行一个数据插入数据库操作 string strSql1 = string. ...

  6. [jquery]ajax最最常用的七个属性

    1.url 类型:String 默认值: 当前页地址.发送请求的地址. 2.data 类型:String 发送到服务器的数据.将自动转换为请求字符串格式.GET 请求中将附加在 URL 后.查看 pr ...

  7. mac OS下 安装MySQL 5.7

    Mac OS X 下 TAR.GZ 方式安装 MySQL 5.7 与 MySQL 5.6 相比, 5.7 版本在安装时有两处不同: 1:初始化方式改变, 从scripts/mysql_install_ ...

  8. CSS过渡效果transition和动画

    一.过渡效果 可以在不适用Flash和js 的情况下实现过渡效果 属性 描述 transition 简写属性,用于在一个属性中设置四个过渡属性 transition-property 规定应用过渡的c ...

  9. sql计算两个时间之间的差,并用时分秒表示

    这是自己写的方法,总觉得会有更好的办法实现这个效果呢? SELECT then ))))+'秒' then )))+'秒' then ))+'秒' else CONVERT(nvarchar,DATE ...

  10. ffmpeg 命令的使用

    当然先安装了 gentoo 下一条命令搞定 emerge  ffmpeg 格式转换 (将file.avi 转换成output.flv) ffmpeg -i  file.avi  output.flv ...