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

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

mid 敲错调了一上午

气炸。。。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <string>
  7. #include <queue>
  8. #include <vector>
  9.  
  10. using namespace std;
  11. const int N = 1e5 + ;
  12.  
  13. #define yxy getchar()
  14. #define lson jd << 1
  15. #define rson jd << 1 | 1
  16.  
  17. #define RR freopen("gg.in", "r", stdin)
  18.  
  19. int n, Ty, Tim, how, ans;
  20. int fa[N], topp[N], deep[N], size[N], son[N], tree[N];
  21. priority_queue <int> Q1[N << ], Q2[N << ];
  22. vector <int> vec[N << ];
  23. struct Node{int up, down;} D[N];
  24. struct Node2{int l, r, val;} Ask[N << ];
  25.  
  26. inline int read() {
  27. int x = ; char c = yxy;
  28. while(c < '' || c > '') c = yxy;
  29. while(c >= '' && c <= '') x = x * + c - '', c = yxy;
  30. return x;
  31. }
  32.  
  33. void Dfs_son(int u, int f_, int dep) {
  34. fa[u] = f_;
  35. deep[u] = dep;
  36. size[u] = ;
  37. int siz_ = vec[u].size();
  38. for(int i = ; i < siz_; i ++) {
  39. int v = vec[u][i];
  40. if(v != f_) {
  41. Dfs_son(v, u, dep + );
  42. size[u] += size[v];
  43. if(size[v] > size[son[u]]) son[u] = v;
  44. }
  45. }
  46. }
  47.  
  48. void Dfs_un(int u, int tp) {
  49. topp[u] = tp;
  50. tree[u] = ++ Tim;
  51. if(!son[u]) return ;
  52. Dfs_un(son[u], tp);
  53. int siz_ = vec[u].size();
  54. for(int i = ; i < siz_; i ++) {
  55. int v = vec[u][i];
  56. if(v != fa[u] && v != son[u]) Dfs_un(v, v);
  57. }
  58. }
  59.  
  60. inline bool cmp(Node a, Node b) {return a.up < b.up;}
  61.  
  62. void Sec_G(int l, int r, int jd, int x, int y, int yj) {
  63. if(x <= l && r <= y) {
  64. if(how == ) Q1[jd].push(yj);
  65. else Q2[jd].push(yj);
  66. return ;
  67. }
  68. int mid = (l + r) >> ;
  69. if(x <= mid) Sec_G(l, mid, lson, x, y, yj);
  70. if(y > mid) Sec_G(mid + , r, rson, x, y, yj);
  71. }
  72.  
  73. inline void Sec_G_imp(int x, int y, int val) {
  74. int tp1 = topp[x], tp2 = topp[y], js();
  75. while(tp1 != tp2) {
  76. if(deep[tp1] < deep[tp2]) swap(x, y), swap(tp1, tp2);
  77. D[++ js].up = tree[tp1];
  78. D[js].down = tree[x];
  79. x = fa[tp1];
  80. tp1 = topp[x];
  81. }
  82. if(deep[x] < deep[y]) swap(x, y);
  83. D[++ js].up = tree[y]; D[js].down = tree[x];
  84. sort(D + , D + js + , cmp);
  85. int last = ;
  86. for(int i = ; i <= js; i ++) {
  87. int l_ = last + , r_ = D[i].up - ;
  88. if(l_ <= r_) Sec_G(, n, , l_, r_, val);
  89. last = D[i].down;
  90. }
  91. int l_ = last + , r_ = n;
  92. if(l_ <= r_) Sec_G(, n, , l_, r_, val);
  93. }
  94.  
  95. int get_answer(int jd) {
  96. int ret = -;
  97. while(!Q2[jd].empty() && (Q1[jd].top() == Q2[jd].top())) Q1[jd].pop(), Q2[jd].pop();
  98. if(Q1[jd].empty()) return -;
  99. return Q1[jd].top();
  100. }
  101.  
  102. void Sec_A(int l, int r, int jd, int x) {
  103. ans = max(ans, get_answer(jd));
  104. if(l == r) return ;
  105. int mid = (l + r) >> ;
  106. if(x <= mid) Sec_A(l, mid, lson, x);
  107. else Sec_A(mid + , r, rson, x);
  108. }
  109.  
  110. int main() {
  111. n = read();
  112. Ty = read();
  113. for(int i = ; i < n; i ++) {
  114. int u = read(), v = read();
  115. vec[u].push_back(v);
  116. vec[v].push_back(u);
  117. }
  118. Dfs_son(, , );
  119. Dfs_un(, );
  120. for(int i = ; i <= Ty; i ++) {
  121. int opt = read();
  122. if(opt == ) { //添加
  123. Ask[i].l = read(), Ask[i].r = read(), Ask[i].val = read();
  124. how = ;
  125. Sec_G_imp(Ask[i].l, Ask[i].r, Ask[i].val);
  126. } else if(opt == ) { //删除
  127. int x = read();
  128. how = -;
  129. Sec_G_imp(Ask[x].l, Ask[x].r, Ask[x].val);
  130. } else { //查询
  131. int x = read();
  132. ans = -;
  133. Sec_A(, n, , tree[x]);
  134. cout << ans << endl;
  135. }
  136. }
  137. return ;
  138. }

[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. Scratch第四十九讲:完美的下落和反弹

    做了很多小游戏,都会遇到碰撞和反弹的情况,CC哥大多时候也都是简单处理一下,包括之前的讲座也有提过,但是没有认真的讲解过.今天就专门为这个主题做一讲,把这部分内容彻底讲透,大家可以一起探讨一下. 是不 ...

  2. ELK日志分析系统的搭建

    一.ELK简介 ELK是Elasticsearch.Logstash.Kibana的简称,这三者是核心组件. Elasticsearch是数据存储.搜索.分析引擎,功能非常强大:Logstash是日志 ...

  3. 美化linux客户端zsh和oh-my-zsh

    linuxbashzshoh-my-zsh 一.安装zsh 二.安装oh-my-zsh 一.安装zsh 安装 zsh yum -y install zsh 替换默认shell chsh -s /bin ...

  4. VBA术语(三)

    在本章中,将介绍常用的Excel VBA术语.这些术语将在很多的模块中使用,因此理解其中的每一个术语都很重要. 模块 模块是编写代码的区域.如下图中,这是一个新的工作簿,因此没有任何模块. 要插入模块 ...

  5. IE6图片透明问题

    网上很多解决IE6下png透明问题的方案,但是经本人实践,有的时候有用,有的时候并不能解决自己的问题.当是后者的时候,想到另外一种办法,就是当在IE6.IE7下使用gif图片,自己在测试的时候,如果g ...

  6. XCode5环境下利用crash log调试线上Crash的流程

    1.前言 本文主要介绍在XCode5环境下,如何根据App自己生成的crashlog来调试真机上运行时产生的crash问题. 2. 步骤 (1)构造一段会crash的代码,并放到viewDidLoad ...

  7. stm32 ds18b20 温度传感器

    相关文章:http://blog.csdn.net/zhangxuechao_/article/details/74991985 举例 void DS18B20_in() { GPIO_InitTyp ...

  8. Netty——基本使用介绍

    https://blog.csdn.net/haoyuyang/article/details/53243785 1.为什么选择Netty 上一篇文章我们已经了解了Socket通信(IO/NIO/AI ...

  9. 【Struts2】Json插件使用

    一.使用步骤 1.1 引入依赖 1.2 在struts.xml文件中配置 一.使用步骤 1.1 引入依赖 <!-- https://mvnrepository.com/artifact/org. ...

  10. 【leetcode】637. Average of Levels in Binary Tree

    原题 Given a non-empty binary tree, return the average value of the nodes on each level in the form of ...