权值线段树
权值线段树 其实权值线段树在学习主席树的时候我就提到过这个东西。 权值线段树和普通线段树之间区别就是在于 它存储的是 区间内数的个数 所以用这种数据结构我们可以求解一个 完整区间的第k大 ,要注意和主席树的区别。 主席树更加强大!! 学了主席树反过来学权值线段树超简单 直接上例题:黑匣子 https://www.luogu.org/problemnew/show/P1801 1 #include <stdio.h> 2 #include <iostream> 3 #include <algorithm> 4 #include <string.h> 5 #include <vector> 6 #include <map> 7 #include <random> 8 #include <sqlite3.h> 9 10 const int maxn = 3e5 + 10 ; 11 12 int k ; 13 int arr [ maxn ]; 14 int u [ maxn ]; 15 16 struct val_segment_tree { 17 int l , r ; 18 int val ; 19 } tree [ maxn << 2 ]; 20 21 void build ( int nod , int l , int r ) { 22 tree [ nod ]. l = l ;