![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
主席树
Nightmare丶
登高必自卑,行远必自迩
展开
-
PowerOJ 2904: kmlver的子串plus
题意: kmlver有一个字符串S, 该字符串仅由小写字母组成,你需要分别回答Q次询问,每次询问由4个整数组成:l1,r1,l2,r2(1≤l1≤r1≤∣S∣,1≤l2≤r2≤∣S∣)l1, r1, l2, r2 (1 ≤ l1 ≤ r1 ≤ |S|, 1 ≤ l2 ≤ r2 ≤ |S|)l1,r1,l2,r2(1≤l1≤r1≤∣S∣,1≤l2≤r2≤∣S∣),你需要统计子串Sl1S_{l_1}Sl1Sl1+1S_{l_1+1}Sl1+1Sl1+2S_{l_1+2}Sl1+2…Sr1S_{r1}原创 2020-10-27 19:02:08 · 168 阅读 · 0 评论 -
HDU 4251 The Famous ICPC Team Again(主席树/划分树)
题意: 给出一个长度为n的序列,m次询问l,r,每次输出区间的中间值 题解: 裸的划分树/主席树,又水了一篇题解真快乐 AC代码: #pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; using namespace __gnu_cxx; typedef long long LL; const int...原创 2019-12-25 16:39:31 · 130 阅读 · 0 评论 -
P2633 Count on a tree(树上主席树)
题解: 主席树是一个类似前缀和的数据结构,具有和前缀和类似的区间加减及差分等性质。 在求解线性区间的第k小数时,我们需要将该区间内的所有数值离散化后扔到一颗主席树中,并在这颗主席树上左右递归,来找到第k小数。 树上类似:用树上每个节点维护它到根的路径上的权值线段树,每个节点用它的父节点更新,dfs建树,套个差分就好了:t[u]+t[v]−t[lca]−t[lcafa]t[u] + t[v] - t...原创 2019-12-10 20:33:40 · 115 阅读 · 0 评论 -
P3567 [POI2014]KUR-Couriers
题意: 给一个数列,每次询问一个区间内有没有一个数出现次数超过一半 n,m≤500000n,m≤500000n,m≤500000 题解: 出现次数,很明显的权值线段树,但是要可持久化,所以直接用主席树维护,判断左右区间中是否存在出现次数超过一半的即可,两边都需要递归下去查找。 AC代码: #include<bits/stdc++.h> using namespace std; con...原创 2019-12-04 19:30:08 · 114 阅读 · 0 评论 -
POJ 2104 K-th Number(主席树)
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...原创 2019-12-03 20:12:44 · 124 阅读 · 0 评论 -
[2019CCPC网络赛][hdu6704] K-th occurrence
Problem Description You are given a string S consisting of only lowercase english letters and some queries. For each query (l,r,k)(l,r,k)(l,r,k), please output the starting position of the k−thk-thk−t...原创 2019-11-13 15:32:54 · 177 阅读 · 0 评论