ICode9

精准搜索请尝试: 精确搜索
  • SPOJ-QTREE3 Query on a tree again!2022-07-08 00:31:22

    Query on a tree again! 树链剖分 + 二分 通过树链剖分查找,判断一下路径上,最后一个黑点出现在哪一条链上,然后在链上进行二分 dfn 查找第一个黑点所在位置 #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int maxn = 1

  • HDU-3966 Aragorn's Story2022-07-03 17:02:18

    Aragorn's Story 树链剖分模板 维护两个点之间路径的值,剖分之后用线段树 区间修改 单点查询 注意初始化(不会有人没初始化边,然后 MLE 了半个小时吧) (为什么是 MLE 而不是 RE!!小编也不太清楚,小编也很想知道,[狗头]) #include <iostream> #include <algorithm> #include <vector> using n

  • 长链剖分2022-02-15 11:03:12

    算法简介 \(\quad\)这个数据结构的重儿子是深度最深的节点,这是它和树链剖分唯一的区别。 \(\quad\)它最经典的应用就是求 k 级祖先,预处理的期望复杂度为 O(nlogn),查询 O(1) \(\quad\)设每个节点的重儿子深度为 hson , 每个轻儿子记录往上 hson 长度路径的信息,每一条链头记录自己这

  • [树链剖分] HDU 6962 I love tree2021-07-25 20:34:31

    题目大意 有一棵 \(n\) 个点的数以及 \(q\) 个操作,每个点的点权初始时为0,操作1将从 \(a\) 到 \(b\) 的路径上点的权值分别加上 \(1,4,9,16,\dots\),操作2询问一个点的点权。\((1\leq n,q\leq 10^5)\) 题解 首先肯定可以用树链剖分来维护。 注意到 \(1,4,9,16,\dots\) 差分后是一个

  • 动态DP(DDP)学习笔记2021-04-24 10:01:12

    动态DP 动态DP就是将 \(DP\) 的状态作为一个向量,\(DP\) 的转移写成一个矩阵,因为矩阵乘法的结合律,我们可以用数据结构维护矩阵的积,然后就能够支持单点修改区间查询了。 洛谷P4719 【模板】"动态 DP"&动态树分治 Description 给定一棵 \(n\) 个点的树,点带点权。 有 \(m\) 次操作,每次

  • [长链剖分优化dp] Codeforces 1499F2021-04-01 18:33:47

    题目大意 给定一棵 \(n(2\leq n\leq 5000)\) 个点的树,求一共有多少种方案,删去若干条边后,分裂出的所有树的直径都不超过 \(K\),答案模 \(998244353\)。 题解 设 \(dp[u][i]\) 表示把以 \(u\) 为根的子树分裂成若干棵直径不超过 \(K\) 的树,且以 \(u\) 为根的树的高度为 \(i\) 的方案

  • cf 1009F2019-08-15 21:01:49

    之前写过一个类似的。600E 考虑到记录的信息与子树的深度是相关的,所以我们长链剖分 不是啊我怎么就快了100ms啊我写了个假的??? 然后启发式合并,更新答案还是蛮好更新的。 #include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 1e6+5; vector<int> g[N

  • BZOJ 4817: [Sdoi2017]树点涂色 LCT+Access的性质+DFS序+线段树2019-06-15 13:49:27

    Code: #include<bits/stdc++.h> #define maxn 200003 #define inf -1000000 using namespace std;void setIO(string s){ string in=s+".in",out=s+".out"; freopen(in.c_str(),"r",stdin); freopen(out.c_str(),"w",stdout

  • BZOJ 4999: This Problem Is Too Simple! DFS序+LCA+树状数组+离线2019-06-13 14:45:27

    Code: #include<bits/stdc++.h>#define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout) #define maxn 300000 using namespace std;struct OPT{ int type; int a,b,c,tag; OPT(int type=0,int

  • luoguP4719 【模板】动态 DP 线段树_树链剖分_矩阵乘法_动态DP2019-06-03 09:53:17

    Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #define maxn 300000 #define lson (now<<1) #define rson ((now<<1)|1) #define ll long long const ll inf = 1e17; using namespace std;int hd[maxn],

  • 【BZOJ5293】[BJOI2018]求和(前缀和,LCA)2019-02-13 11:53:33

    【BZOJ5293】[BJOI2018]求和(前缀和,LCA) 题面 BZOJ 洛谷 题解 送分题??? 预处理一下\(k\)次方的前缀和。 然后求个\(LCA\)就做完了?、、、 #include<iostream> #include<cstdio> using namespace std; #define MOD 998244353 #define MAX 300300 inline int read() { int x=0;bool t=

  • 【BZOJ5212】[ZJOI2018]历史(Link-Cut Tree)2019-02-02 21:42:56

    【BZOJ5212】[ZJOI2018]历史(Link-Cut Tree) 题面 洛谷 BZOJ 题解 显然实际上就是给定了一棵树和每个点被\(access\)的次数,求解轻重链切换的最大次数。 先考虑不带修改的答案。 如果直接考虑全局的答案会很麻烦。 考虑每一个在每一个点处被切换的次数。 显然这个子树之和其子树内的点

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有