数据结构
文章平均质量分 53
Weach
学生
展开
-
AcWing 248. 窗内的星星(线段树 -- 扫描线)
AcWing 248. 窗内的星星思路:对于给定的点(星星)我们将他作为矩形的左下角构造两条线段 seg左(x,y,y+h-1,c) seg右(x+w-1,y,y+h-1,-c)然后线段树维护最大值#include<bits/stdc++.h>#include <unordered_map> using namespace std;template<class...Args>void debug(Args... args) {//Paramete原创 2021-12-01 21:51:35 · 92 阅读 · 0 评论 -
Codeforces Round #149 (Div. 2) E. XOR on Segment --二进制按位建树
Codeforces Round #149 (Div. 2) E. XOR on Segment#include<bits/stdc++.h> #include <unordered_map> using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ',原创 2021-11-29 20:00:55 · 499 阅读 · 0 评论 -
FZU2105 Digits Count --线段树(区间与、或、异或)
FZU2105 Digits CountGiven N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations:Operation 1: AND opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] AND opn (here "AND" is bitwise operation).Operation 2: OR opn L RHere o原创 2021-10-29 15:32:09 · 280 阅读 · 0 评论 -
HDU 4578 - Transformation -- 线段树区间修改(p次方和,二进制每位建树)
HDU 4578 - Transformation题意:给你一个数组,初始值为零,有四种操作1)“1 x y c”,代表 把区间 [x,y] 上的值全部加c2)“2 x y c”,代表 把区间 [x,y] 上的值全部乘以c3)“3 x y c”, 代表 把区间 [x,y]上的值全部赋值为c4)“4 x y p”,代表 求区间 [x,y] 上值的p次方和1<=p<=3思路:注意到p最多只有3因此我们可以在每个节点中维护好这个节点区间所有数和的1,2,3次方而对于操作1,2,3我原创 2021-10-26 20:48:30 · 97 阅读 · 0 评论 -
HUD 3308 LCIS -- 线段树
HUD 3308 LCIS#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";}ty原创 2021-10-19 15:20:35 · 92 阅读 · 0 评论 -
POJ 3667 Hotel -- 线段树
POJ 3667 Hotel //#include<bits/stdc++.h>#include<iostream>//#include <unordered_map>#include<algorithm>using namespace std;//template<class...Args>//void debug(Args... args) {//Parameter pack// auto tmp = { (cout &l原创 2021-10-18 17:38:31 · 77 阅读 · 0 评论 -
codeforces Sum of Medians -- 线段树
D. Sum of Medians有三种类型的操作(1)“add x”,表示往集合里添加数x。(2)“del x”,表示将集合中数x删除。(3)“sum”,求出从小到大排列的集合中下标模5为3的数的和。集合中的数都是唯一的线段树维护某个区间的数的个数cnt,再维护区间区间内数%5相同的和mod_sum#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<clas原创 2021-10-16 19:58:48 · 138 阅读 · 0 评论 -
hdu 2795 Billboard -- 线段树
hdu 2795 Billboard以h建立线段树维护最大值每个节点初始化最大值为w对于每次改,从最左端开始找满足要求的位置//#include<bits/stdc++.h>#include<iostream>#include<vector>//#include <unordered_map>using namespace std;//template<class...Args>//void debug(Args... args)原创 2021-10-15 21:28:06 · 114 阅读 · 0 评论 -
POJ 2828 Buy Tickets --线段树
POJ2828 Buy Tickets后面以此类推则我们每次查找的是排除确定好的pos后对应的新pos所在数组的位置用ans数组存值即可//#include<bits/stdc++.h>#include<iostream>#include<vector>//#include <unordered_map>using namespace std;//template<class...Args>//void debug(Args..原创 2021-10-14 21:46:18 · 113 阅读 · 0 评论 -
HDU 1698 Just a Hook--线段树
题意:给你T组数据,N个数(初始时每个数的值为1),M个操作,每个操作把区间[a,b]里的数更新为c,问最后这N个数的和是多少题解:懒标记维护下即可#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout <原创 2021-10-13 17:05:33 · 84 阅读 · 0 评论 -
2021中国大学生程序设计竞赛(CCPC)- 网络选拔赛(重赛)Monopoly
HDU 7130 Monopoly对于题目来说我们要有一个前缀和sum[i]sum[i]sum[i]:代表每走一步能得到的价值一个总和SSS:走完一轮后的总和一个set<ll>bucket[N]set<ll>bucket[N]set<ll>bucket[N]:(桶)存放前缀和模S相同的数的集合一个map<ll,ll>_hashmap<ll, ll>\_hashmap<ll,ll>_hash:模数转化为桶的位置(离散化)一个m原创 2021-10-12 20:52:17 · 453 阅读 · 5 评论 -
2018湖南省省赛 H 千万别用树套树--线段树\树状数组
求区间[l,r][l,r][l,r]满足条件的线段问题转化为求1.区间[l+1,n][l+1,n][l+1,n]中存在多少条线段的左端点(这个区间的有线段的左端点出现说明者条线段不完全覆盖)2.区间[1,r−1][1,r-1][1,r−1]中存在多少条线段的右端点(同理上)答案等于当前线段的条数减去上面不满足要求的条数(容斥原理)用简单的权值线段树维护上述值#include<bits/stdc++.h>#include <unordered_map>using nam原创 2021-10-04 20:12:20 · 81 阅读 · 0 评论 -
The 2021 ICPC Asia Regionals Online Contest (I) A Busiest Computing Nodes--线段树
题意:某系统有k个内存块,用户提出了n个请求,每个内存块每次只能处理一个请求。如果某个请求到达时,所有内存块都被占用,则该请求被忽略(永不被执行),否则将该请求交给某个内存块处理(从i%k,(i+1)%k ,个块依次循环向右查找第一个空闲的块,然后把当前请求提交给这个块)。试求处理请求最多的内存块号。#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Ar原创 2021-09-24 20:05:33 · 302 阅读 · 0 评论 -
The 17th Zhejiang Provincial Collegiate Programming Contest C Crossword Validation--字典树
The 17th Zhejiang Provincial Collegiate Programming Contest #include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args <原创 2021-08-13 10:35:03 · 210 阅读 · 0 评论 -
The 17th Zhejiang Provincial Collegiate Programming Contest E Easy DP Problem--主席树
The 17th Zhejiang Provincial Collegiate Programming Contest E Easy DP Problem#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout原创 2021-08-12 17:43:56 · 229 阅读 · 0 评论 -
The 17th Zhejiang Provincial Collegiate Programming Contest B. Bin Packing Problem--线段树
The 17th Zhejiang Provincial Collegiate Programming Contest B. Bin Packing Problem#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (c原创 2021-08-12 11:47:33 · 144 阅读 · 0 评论 -
Mobile phones 1195--二维树状数组
Mobile phones 1195#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";原创 2021-08-09 19:37:48 · 124 阅读 · 0 评论 -
Different GCD Subarray Query--线段树
Different GCD Subarray Query对于一段连续的区间求gcd的情况, 不同的gcd取值最多只有log值域个原创 2021-08-07 21:23:34 · 69 阅读 · 0 评论 -
2016湖南省省赛 G--线段树
G Parenthesis#include<bits/stdc++.h>#include <unordered_map>#include<iostream>#include<algorithm>#include<set>#include<vector>using namespace std;template<class...Args>void debug(Args... args) {//Parameter原创 2021-08-07 20:57:04 · 80 阅读 · 0 评论 -
Mayor‘s posters--线段树染色
Mayor’s posters#include<iostream>#include<algorithm>#include<set>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<ll, ll>pll;typedef pair<int, int>pii;const原创 2021-08-07 17:29:21 · 421 阅读 · 0 评论 -
权值线段树
P1908 逆序对#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";}typede原创 2021-08-06 11:29:44 · 152 阅读 · 0 评论 -
The 16th Heilongjiang Provincial Collegiate Programming Contest A And RMQ --线段树
The 16th Heilongjiang Provincial Collegiate Programming Contest#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args &原创 2021-08-05 21:09:31 · 478 阅读 · 1 评论 -
2019 湖南省省赛 K 双向链表练习题
2019 湖南省省赛 K 双向链表练习题#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n原创 2021-08-04 15:35:57 · 138 阅读 · 0 评论 -
2021 Xinjiang Provincial Collegiate Programming Contest D. cocktail with swap --并查集
#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";}typedef long lon原创 2021-08-01 11:26:03 · 323 阅读 · 0 评论 -
珂朵莉树--区间推平
先来占个坑????#include <iostream>#include <set>#include <algorithm>#include <vector>#include <cstdio>using namespace std;typedef long long ll;const ll MOD = 1000000007;const ll MAXN = 100005;struct Node { ll l, r;/原创 2021-07-30 20:59:41 · 218 阅读 · 0 评论 -
吉司机线段树--区间最值操作
区间最值操作给定一个长度为 N序列,编号从1 到 N。要求支持下面几种操作:1.给一个区间[L,R] 加上一个数x2.把一个区间[L,R] 里小于x 的数变成x3.把一个区间[L,R] 里大于x 的数变成x4.求区间[L,R] 的和5.求区间[L,R] 的最大值6.求区间[L,R] 的最小值最假女选手#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<c原创 2021-07-30 19:40:32 · 494 阅读 · 0 评论 -
李超线段树
什么是李超线段树先以一个问题引入:在平面上有两种操作(强制在线):插入一条表达式为 L : y = k*x+b 的直线,给出 k ,b 。给出 t,求当前所有直线中与直线 x = t 交点的纵坐标最大是多少直线取 max 应该是得到一个下凸包,像这样(黑色的):李超线段树是什么?线段树,当然是要维护区间 [L , R] 的一个信息,李超线段树维护的就是中点处最高的直线比如下图,区间 [ 0 , 4 ] 的中点 x = 2 的最高直线为红色直线利用这一信息,可以在 O(log n )原创 2021-07-29 20:27:58 · 3919 阅读 · 1 评论 -
可持久化数据结构--线段树/主席树
模拟一组数据7 11 5 2 6 3 7 42 5 31.首先建立基树逐一插入数字,将每个数字的大小(即离散化后的编号)插入到它的位子上,然后并把所有包括它的区间的和标记都++最后插入4时接下来我们考虑查询。要查询[2, 5]中第3大的数我们首先把第1棵线段树和第5棵拿出来然后我们发现,将对应节点的数相减,刚刚好就是[2, 5]内某个范围内的数的个数。比如[1, 4]这个节点相减是2,就说明[2. 5]内有2个数是在1~4范围内(就是2, 3)。所以对于一个区间[l, r],原创 2021-07-26 15:50:45 · 163 阅读 · 2 评论 -
可持久化数据结构--tire
先占个坑????插入rat后的版本2插入cab后的版本3插入frg后的版本4原创 2021-07-25 10:29:14 · 108 阅读 · 1 评论 -
The 15th Chinese Northeast Collegiate Programming Contest D. Lowbit --线段树
The 15th Chinese Northeast Collegiate Programming Contest D. Lowbit题目大意:对于给定序列有两种操作1 L R :修改区间[ L , R ]内的每个元素的值使其加上本身的lowbit值2 L R :询问区间[ L , R ]的和思路:乍一看被难住在操作 1 上区间内每个元素都要加上其本身的lowbit值,这不是退化到单点修改了吗,单点修改必然超时但通过lowbit性质可知int lowbit(int x) { // x原创 2021-07-24 11:50:36 · 358 阅读 · 0 评论 -
线段树总结
确定线段树维护的信息根据题意设计节点所需要维护的信息,可以设计多个其目的是维护最终信息,但每个信息可简单方便的求出如求区间最大连续子段和时如何设计维护的线段树:struct node { ll l, r; ll totmx;//最大连续子段和 ll lmax;//最大前缀和 ll rmax;//最大后缀和 ll sum;//区间和}tree[N << 2];设计push_up()函数在左右儿子信息正确的情况下如何更新父节点信息如求区间最大原创 2021-07-24 11:33:42 · 67 阅读 · 0 评论 -
数据结构之 BST 手写treap
AcWing 253. 普通平衡树#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";原创 2021-07-21 10:28:28 · 100 阅读 · 0 评论 -
线段树--线扫描
AcWing 247. 亚特兰蒂斯HDU 1542 Atlantis#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; c原创 2021-07-19 17:11:09 · 243 阅读 · 0 评论 -
线段树--区间最大连续子段和
AcWing 245. 你能回答这些问题吗#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "原创 2021-07-18 10:46:50 · 227 阅读 · 0 评论 -
AcWing 244. 谜一样的牛--二分+树状数组
AcWing 244. 谜一样的牛#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";原创 2021-07-17 15:11:51 · 72 阅读 · 0 评论 -
AcWing 1252. 搭配购买--并查集+01背包
AcWing 1252. 搭配购买#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";原创 2021-07-16 17:27:52 · 101 阅读 · 0 评论 -
AcWing 841. 字符串哈希
AcWing 841. 字符串哈希#include<bits/stdc++.h>#include <unordered_map>using namespace std;template<class...Args>void debug(Args... args) {//Parameter pack auto tmp = { (cout << args << ' ', 0)... }; cout << "\n";原创 2021-07-16 11:30:37 · 92 阅读 · 2 评论 -
AcWing 840. 模拟散列表--哈希表
AcWing 840. 模拟散列表拉链法#include<bits/stdc++.h>#include <unordered_map>using namespace std;template <typename T> void debug(string s, T x) { cout << s << "=" << x << "\n"; }typedef long long ll;typedef unsigned原创 2021-07-15 10:47:30 · 126 阅读 · 0 评论 -
AcWing 839. 模拟堆--手写堆
AcWing 839. 模拟堆#include<bits/stdc++.h>#include <unordered_map>using namespace std;template <typename T> void debug(string s, T x) { cout << s << "=" << x << "\n"; }typedef long long ll;typedef unsigned long l原创 2021-07-15 09:33:46 · 95 阅读 · 0 评论 -
AcWing 838. 堆排序
AcWing 838. 堆排序#include<bits/stdc++.h>#include <unordered_map>using namespace std;template <typename T> void debug(string s, T x) { cout << s << "=" << x << "\n"; }typedef long long ll;typedef unsigned long原创 2021-07-15 09:32:52 · 61 阅读 · 0 评论