相关链接
题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4059
神犇题解Ⅰ:http://blog.csdn.net/popoqqq/article/details/46380617
神犇题解Ⅱ:http://krydom.com/bzoj4059/
解题报告
考虑直接找出所有不无聊的区间
直接 $ O(n^2)$ 枚举的话,会T掉,于是考虑分治
假如当前考虑到的区间为(l,r),且这个区间中一个只出现过一次的数为x,下标为p
那么显然,横跨x的区间合法,两边的区间就递归下去做就好啦!
但如果每一次我们从左到右扫描x的话,时间复杂度长这样:$ T(n) = T(n – 1) + n$
这样的话,上限是 $ O(n^2)$ 显然不清真
考虑同时从两边开始扫描的话,复杂度就变为了: $ T(n) = T(p) + T(n – p) + \min (n – p,p)$
于是这个是:$ O(n\log n)$ 的,于是就可以愉快的暴力啦!
至于复杂度的证明的话,我们发现这货的形式和线段树的启发式合并的式子长得一毛一样
因为线段树的启发式合并是 $ O(n\log n)$ 的,那么这货的复杂度也就是对的啦!
当然你也可以使用归纳法什么的来证明复杂度
甚至你可以根本不用这个暴力的算法,而使用优雅的矩形面积并来做:
http://www.cnblogs.com/DaD3zZ-Beyonder/p/5803964.html
Hi there! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new updates.
I think other site proprietors should take this site as an model, very clean and wonderful user genial style and design, let alone the content. You’re an expert in this topic!
384498 101693This web internet site is often a walk-through for all with the understanding you wanted concerning this and didnt know who need to. Glimpse here, and you will absolutely discover it. 779651
430100 129436quite nice post, i in fact love this web internet site, carry on it 649396
953322 620509You created some respectable points there. I looked on the internet for the problem and found most people will go along with along with your website. 471444
165303 34868Greatest fighter toasts ought to entertain and supply prize on your couples. Initially audio system next to obnoxious crowd would be wise to comprehend 1 specific gold colored strategy as to public speaking, which is individual interests self. very best man jokes 681733
461301 59459you made blogging glance 568579
851569 723860conclusion that you are absolutely correct but a couple of need to be 516226
602452 58280Hello my family member! I wish to say that this post is incredible, wonderful written and come with approximately all vital infos. I would like to see extra posts like this . 281937
854185 930233I believe other site proprietors ought to take this internet site as an model, quite clean and superb user genial style . 212721
711020 665887I was seeking at some of your weblog posts on this site and I believe this internet site is real instructive! Keep posting . 893266
688192 481758I view something genuinely special in this website . 673000
478637 204469Its truly a cool and beneficial piece of info. Im glad that you shared this useful details with us. Please maintain us informed like this. Thanks for sharing. 224566