POJ 2892 Tunnel Warfare (SBT + stack)】的更多相关文章

题意:给定了初始的状态:有n个村庄连成一条直线,现在有三种操作: 1.摧毁一个村庄 2.询问某个村庄,输出与该村庄相连的村庄数量(包括自己) 3.修复被摧毁的村庄,优先修复最近被摧毁的.............. 分析:用SBT做的话,摧毁村庄就插入,修复就移除,如果要询问的话:找到第一个大于等于该村庄编号和第一个小于等于该村庄编号的,等价于找到了联通在一起的村庄. 朴素的做法可以 set + stack + 二分 搞之................. #include <iostream>…
Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally sp…
Tunnel Warfare                                                             Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)                                                                                            …
传送门 很神奇的一道题,可以用线段树搞,为了练习treap所以拿treap写了. 其实根据询问,删除那个标号就加入平衡树,然后找到最大的和最小的就好了. 一些很烦人的小细节. //POJ 2892 //by Cydiater //2016.9.1 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #includ…
题意:一条线上有n个点,D x是破坏这个点,Q x是表示查询x所在的最长的连续的点的个数,R是恢复上一次破坏的点. 思路:这题的关键是查询. 将被毁的村庄看成空位,当查询某个点的时候,如果我们知道它左边最近的空位a和右边最近的空位b, 那么我们只要查询区间[a,b]中的个数,即为答案,因为[a,b]之间不可能有空位存在了. 那么如何获取这样的a和b呢,这个就和HDU 4302 Holedox Eating 差不多了. 对每个节点,存储该区间中 空位的最大位置 和 空位的最小位置,还有 该区间村庄…
Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7499   Accepted: 3096 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally sp…
线段树 区间合并 单点修改 区间查询.又是1秒钟构思,差错查了好久... ... 发现一个int型的定义成了char型,打脸. #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set&…
题目链接 二分求上界和下界,树状数组.注意特殊情况. #include <cstring> #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> using namespace std; ]; ]; ]; int n; int lowbit(int t) { return t&(-t); }…
点我看题目 题意 :N个村子连成一条线,相邻的村子都有直接的地道进行相连,不相连的都由地道间接相连,三个命令,D x,表示x村庄被摧毁,R  ,表示最后被摧毁的村庄已经重建了,Q x表示,与x直接或间接相连的村庄有多少个,当然包括他自己. 思路 :这是一道用线段树,树状数组,还有STL都可以做的题....因为用线段树的更新什么的太麻烦,.....所以我用了树状数组 #include <iostream> #include <stdio.h> #include <string.…
[算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorithm> #include<ctime> using namespace std; ; ]; int n,m,root,sz,s,tt,d[maxn]; void rr(int &tt)//右旋 { int k=t[tt].l; t[tt].l=t[k].r; t[k].r=tt; tt…