我用的是此题的树链剖分方法,此题时限50S。。。。
首先将树按链重新标号,然后将一段链给放到线段树中取。由于求u到v的k大值,那么我们可以对于一段链中二分查找对于某一个值小于这个值的个数有多少个,那么我们就可以知道这个值如果恰好是第k大的就是答案所求。用线段树的话可以将一段区间的值快速求出来
实现就是对于线段树表示表示区间的节点,对于那一段区间我们建立一个二叉搜索树(我用的treap,用于统计大于某个值的个数有多少个),然后对于每一个二分答案,我们对于这个值在u到v的树链上求小于这个值的答案有多少个就好了,直接按树链剖分的方法往一端靠上去求累计和就好了。
其总的复杂度是n(logn)^4其实想想这个复杂度对于一组数据已经接近n^2了但是考虑到线段树的区间更新,我们其实区间的查询能大大提高效率,20s可以过
这题思路这样差不多就很好写了,就是编码复杂点了。。。
这里建树忧伤死我了。。。。下面是我写treap的过程。。。
1、treap答案最多的有80000个节点,最开始的方法是treap建立静态的数组,但是考虑线段树是8000*4在加上每个treap起码有8000*(2+3)大小, 开不下。。。。。忧伤啊
2、然后我又写了个c++动态生成数组的treap,每次生成线段树r-l+4的数组大小,但是任然是静态的内存池,过到了第7组就re了,因为我发现每次删除一个节点后在生成节点内存池下标往后走。。。忧伤
http://www.songtaste.com/user/9109640/info
http://www.songtaste.com/user/9109645/info
http://www.songtaste.com/user/9109653/info
http://www.songtaste.com/user/9109663/info
http://www.songtaste.com/user/9109664/info
http://www.songtaste.com/user/9109720/info
http://www.songtaste.com/user/9109725/info
http://www.songtaste.com/user/9109730/info
http://www.songtaste.com/user/9109784/info
http://www.songtaste.com/user/9109788/info
http://www.songtaste.com/user/9109791/info
http://www.songtaste.com/user/9109804/info
http://www.songtaste.com/user/9109818/info
http://www.songtaste.com/user/9109845/info
http://www.songtaste.com/user/9109862/info
http://www.songtaste.com/user/9109873/info
http://www.songtaste.com/user/9109888/info
http://www.songtaste.com/user/9109942/info
http://www.songtaste.com/user/9109946/info
http://www.songtaste.com/user/9109948/info
http://www.songtaste.com/user/9109953/info
http://www.songtaste.com/user/9109991/info
http://www.songtaste.com/user/9109995/info
http://www.songtaste.com/user/9110018/info
http://www.songtaste.com/user/9110039/info
http://www.songtaste.com/user/9110047/info
http://www.songtaste.com/user/9110049/info
http://www.songtaste.com/user/9110059/info
http://www.songtaste.com/user/9110111/info
http://www.songtaste.com/user/9110122/info
http://www.songtaste.com/user/9110146/info
http://www.songtaste.com/user/9110154/info
http://www.songtaste.com/user/9110184/info
http://www.songtaste.com/user/9110195/info
http://www.songtaste.com/user/9110216/info
http://www.songtaste.com/user/9110219/info
http://www.songtaste.com/user/9110222/info
http://www.songtaste.com/user/9110244/info
http://www.songtaste.com/user/9110262/info
http://www.songtaste.com/user/9110285/info
http://www.songtaste.com/user/9110289/info
http://www.songtaste.com/user/9110293/info
http://www.songtaste.com/user/9110294/info
http://www.songtaste.com/user/9110323/info
http://www.songtaste.com/user/9110345/info
http://www.songtaste.com/user/9110364/info
http://www.songtaste.com/user/9110365/info
http://www.songtaste.com/user/9110398/info
http://www.songtaste.com/user/9110444/info
http://www.songtaste.com/user/9110450/info
http://www.songtaste.com/user/9110456/info
http://www.songtaste.com/user/9110474/info
http://www.songtaste.com/user/9110483/info
http://www.songtaste.com/user/9110489/info
http://www.songtaste.com/user/9110491/info
http://www.songtaste.com/user/9110520/info
http://www.songtaste.com/user/9110527/info
http://www.songtaste.com/user/9110536/info
http://www.songtaste.com/user/9110556/info
http://www.songtaste.com/user/9110558/info
http://www.songtaste.com/user/9110569/info
http://www.songtaste.com/user/9110574/info
http://www.songtaste.com/user/9110582/info
http://www.songtaste.com/user/9110591/info
http://www.songtaste.com/user/9110641/info
http://www.songtaste.com/user/9110659/info
http://www.songtaste.com/user/9110664/info
http://www.songtaste.com/user/9110680/info
http://www.songtaste.com/user/9110755/info
http://www.songtaste.com/user/9110756/info
http://www.songtaste.com/user/9110760/info
http://www.songtaste.com/user/9110764/info
http://www.songtaste.com/user/9110774/info
http://www.songtaste.com/user/9110786/info
http://www.songtaste.com/user/9110803/info
http://www.songtaste.com/user/9110805/info
http://www.songtaste.com/user/9110810/info
http://www.songtaste.com/user/9110854/info
http://www.songtaste.com/user/9110894/info
http://www.songtaste.com/user/9110896/info
http://www.songtaste.com/user/9110899/info
http://www.songtaste.com/user/9110911/info
http://www.songtaste.com/user/9110927/info
http://www.songtaste.com/user/9110953/info
http://www.songtaste.com/user/9110965/info
http://www.songtaste.com/user/9110971/info
http://www.songtaste.com/user/9110988/info
http://www.songtaste.com/user/9111017/info
http://www.songtaste.com/user/9111025/info
http://www.songtaste.com/user/9111040/info
http://www.songtaste.com/user/9111041/info
http://www.songtaste.com/user/9111042/info
http://www.songtaste.com/user/9111053/info
http://www.songtaste.com/user/9111068/info
http://www.songtaste.com/user/9111087/info
http://www.songtaste.com/user/9111103/info
http://www.songtaste.com/user/9111108/info
http://www.songtaste.com/user/9111121/info
http://www.songtaste.com/user/9111139/info
http://www.songtaste.com/user/9111151/info
http://www.songtaste.com/user/9111166/info
http://www.songtaste.com/user/9111183/info
http://www.songtaste.com/user/9111202/info
http://www.songtaste.com/user/9111224/info
http://www.songtaste.com/user/9111225/info
http://www.songtaste.com/user/9111248/info
http://www.songtaste.com/user/9111336/info
http://www.songtaste.com/user/9112740/info
http://www.songtaste.com/user/9112741/info
http://www.songtaste.com/user/9112742/info
http://www.songtaste.com/user/9112748/info
http://www.songtaste.com/user/9112754/info
http://www.songtaste.com/user/9112761/info
http://www.songtaste.com/user/9112767/info
http://www.songtaste.com/user/9112779/info
http://www.songtaste.com/user/9112797/info
http://www.songtaste.com/user/9112802/info
http://www.songtaste.com/user/9112803/info
http://www.songtaste.com/user/9112804/info
http://www.songtaste.com/user/9112818/info
http://www.songtaste.com/user/9112819/info
http://www.songtaste.com/user/9112825/info
http://www.songtaste.com/user/9112840/info
http://www.songtaste.com/user/9112849/info
http://www.songtaste.com/user/9112850/info
http://www.songtaste.com/user/9112861/info
http://www.songtaste.com/user/9112863/info
http://www.songtaste.com/user/9112867/info
http://www.songtaste.com/user/9112874/info
http://www.songtaste.com/user/9112879/info
http://www.songtaste.com/user/9112887/info
http://www.songtaste.com/user/9112900/info
http://www.songtaste.com/user/9112903/info
http://www.songtaste.com/user/9112906/info
http://www.songtaste.com/user/9112909/info
http://www.songtaste.com/user/9112915/info
http://www.songtaste.com/user/9112927/info
http://www.songtaste.com/user/9112925/info
http://www.songtaste.com/user/9112936/info
http://www.songtaste.com/user/9112946/info
http://www.songtaste.com/user/9112952/info
http://www.songtaste.com/user/9112962/info
http://www.songtaste.com/user/9112968/info
http://www.songtaste.com/user/9112996/info
http://www.songtaste.com/user/9113007/info
http://www.songtaste.com/user/9113009/info
http://www.songtaste.com/user/9113018/info
http://www.songtaste.com/user/9113019/info
http://www.songtaste.com/user/9113022/info
http://www.songtaste.com/user/9113024/info
http://www.songtaste.com/user/9113035/info
http://www.songtaste.com/user/9113039/info
http://www.songtaste.com/user/9113050/info
http://www.songtaste.com/user/9113055/info
http://www.songtaste.com/user/9113074/info
http://www.songtaste.com/user/9113080/info
http://www.songtaste.com/user/9113086/info
http://www.songtaste.com/user/9113087/info
http://www.songtaste.com/user/9113095/info
http://www.songtaste.com/user/9113101/info
http://www.songtaste.com/user/9113109/info
http://www.songtaste.com/user/9113124/info
http://www.songtaste.com/user/9113126/info
http://www.songtaste.com/user/9113123/info
http://www.songtaste.com/user/9113143/info
http://www.songtaste.com/user/9113149/info
http://www.songtaste.com/user/9111347/info