传送门:https://www.luogu.org/problemnew/show/P3834 题目描述 如题,给定N个整数构成的序列,将对于指定的闭区间查询其区间内的第K小值. 分析 很多人都说是用主席树来维护,一开始蒟蒻chh做这道题的时候还以为是分块乱搞,但是发现常数非常的大,就转用主席树了.这道题我们维护的主席树是一个权值线段树,意思就是维护一个桶,那么我们手动模拟主席树的建树过程,可以发现如果我们要查询区间\([l,r]\),那么发现编号为l-1的主席树和编号为r的主席树上对应的链上的…
JYF大佬说,一星期要写很多篇博客才会有人看 但是我做题没有那么快啊QwQ Part1 写在前面 区间第K小问题一直是主席树经典题=w=今天的重点是动态区间第K小问题.静态问题要求查询一个区间内的第k小的值(可重),动态问题还要求支持单点修改操作. 这个问题也可以用线段树+Splay/整体二分解决,然而那些对蒟蒻来说都太难辣QwQ,这里给一个XZY大佬的整体二分的讲解传送门 我们的做法是主席树+树状数组,如果有不会主席树的同学可以看我之前写的博客=w=,由于静态问题是动态问题的基础,所以我会先讲…
题目链接:http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 64277   Accepted: 22615 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After faili…
题目链接 题解 主席树入门题 但是这里给出整体二分解法 整体二分顾名思义是把所有操作放在一起二分 想想,如果求\([1-n]\)的第\(k\)小怎么二分求得? 我们可以二分答案\(k\), \(O(n)\)统计有多少个数小于等于\(k\) 如果对于每个询问都这么搞,肯定不行 我们可以发现,如果每次都搞一次,有许多算重复的地方 \(div(l, r, st, ed)\)表示\(k\)二分的区间\([l-r]\), 对应操作答案区间在\([st-ed]\) (如果没看懂,先往下看.) \(mid =…
传送门主席树 #include <bits/stdc++.h> #define int long long using namespace std; const int maxn=2e5+5; int n,m,a[maxn]; vector<int> v;//从0开始编号 inline int getid(int x)//得到值为x的编号 { return lower_bound(v.begin(),v.end(),x)-v.begin()+1;//lower_bound找到第一个…
题目大意 给定一个有N个数字的序列,然后又m个查询,形式如下: l r k 要求你返回区间[l,r]第k小的数是哪个 题解 终于弄懂主席树是个啥东西了,O(∩_∩)O~~,这题正是主席树的裸题,主席树具体是啥东西,可以去看CLJ的论文~~~~ 代码是学习haha593572013大神的~~~ 代码: #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> us…
题目链接 //离散化后范围1~cnt不要错 #include<cstdio> #include<cctype> #include<algorithm> //#define gc() getchar() #define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++) const int N=2e5+5,MAXIN=2e6; int n,m,A[N],ref[N],cn…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2665 代码: //#include<bits/stdc++.h> #include<iostream> #include<cmath> #include<algorithm> #define fi first #define se second #define INF 0x3f3f3f3f #define fio ios::sync_with_stdio(fal…
蒟蒻终于学会整体二分啦! 思路 实现 丑陋无比的代码 #include <bits/stdc++.h> using namespace std; const int N = 200005; int ar[N]; int lowbit(int t) { return t & (-t); } void add(int i, int v) { for (; i < N; ar[i] += v, i += lowbit(i)); } int sum(int i) { int s = 0;…
Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array…