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. zookeeper-waches

    1. 设置watches data watches: getData() exist() child watches: getChildren() 2. 触发watches setData(): da ...

  2. 小程序文案过长,‘收起/展开’文字,createSelectorQuery 获取节点成功,boundingClientRect 返回信息null

    问题描述: wxml中id是动态生成的. 获取节点信息是在onReady生命周期函数内延时500ms执行的,select(id)可以获取全部节点信息,boundingClientRect (rect) ...

  3. 怎样手写一个Object.create()方法

    Object.create()会将参数对象作为一个新创建的空对象的原型, 并返回这个空对象, 基于这个功能, 就有了下面这个Object.create()的手动实现: function _create ...

  4. hdu 4745 two Rabits

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4745 题解:首先要抽象出题目要求的是啥.首先对于环的问题, 我们可以倍增成链,然后环的所有情况可以通过链来 ...

  5. hdu 1002 prime 模板

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. hdu 2647 还是逆向拓扑

    Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he ...

  7. 【爬虫集合】Python爬虫

    一.爬虫学习教程 1. https://www.jianshu.com/u/c32d557edfa3 2. WebMagic是一个简单灵活的Java爬虫框架.基于WebMagic,你可以快速开发出一个 ...

  8. (十一)mybatis之整合ehcache缓存

    一.二级缓存 大家都知道使用mybatis就要先获取sqlsessionfactory,继而使用sqlsession来和数据库交互,每次只需要使用sqlsession对象提供的方法就好,当我们需要第一 ...

  9. 关于WEB前端开发的思考与感悟

    万事开头难. 当我想要认真写一篇文章向大家分享我对前端的认识与感悟的时候,突然就深刻的体会到了这句话确实太有道理了. 最近几年对于web前端的传闻很多,比如人才稀缺,简单易学,待遇丰厚,整体势头发展良 ...

  10. CSS 样式表{二}

    1 选择器的优先级 选择器的优先主要考虑选择器的权重 可以将各种选择器的权重以数值来表示,数值越大,优先级越高 选择器 权重值 标签selector 1 类选择器 10 ID选择器 100 行内样式 ...