用vector进行插入和删除操作! 总是有些地方处理不好,对拍了才知道错在哪里,, /* 给定一些操作 reset 清空 new a ,申请最左边的连续a个空间 free a,清空a所在的块 get x,求第x块的起始地址 用个vector<pair<int,int> >记录第i个块的覆盖区间 new时二分找到a所在的pair,进行insert 清空时二分找到a所在的pair,进行erase即可 求第x块的起始地址只要去vector里找一下即可 */ #include<bit…
poj3667 HotelTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 18925 Accepted: 8242Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessi…
两道题都是线段树的区间合并 lsum, rsum分别表示左/右端点 开始向右/左 符合条件的元素的最长连续长度 sum表示这个区间的符合条件的元素的最长连续长度 所以pushUp可写: void pushUp(int root, int l, int r) { ; , lenl = len - lenr; lsum[root] = lsum[lson]; rsum[root] = rsum[rson]; if (lsum[root] == lenl) lsum[root] += lsum[rso…
//Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <cmath> #include <algorithm> using namespace std; /** * This is a documentation comment block * 如果…
题目链接:传送门 参考文章:传送门 思路:线段树区间合并问题,每次查询到满足线段树的区间最左值,然后更新线段树. #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; ],rsum[maxn<<],msum[maxn<<],cover[maxn<<]; void build(int x,int l,int r) { lsum[x]=rs…
题目链接: http://poj.org/problem?id=3667 题意:第一行输入 n, m表示有 n 间房间(连成一排的), 接下来有 m 行输入, 对于接下来的 m 行输入: 1 x : 询问是否有长度为 x 的连号空房, 若有, 住进最左边并输出对应编号: 2 x y : 将区间 [x, x + y - 1] 的房间清空: 思路: 并查集区间合并&区间查询 下面一段题解摘自: http://www.cnblogs.com/scau20110726/archive/2013/05/0…
Tunnel Warfare                                  Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast…
开始以为是水题,结果...... 给你一些只有两种颜色的石头,0为白色,1为黑色. 然后两个操作: 1 l r 将[ l , r ]内的颜色取反 0 l r 计算[ l , r ]内最长连续黑色石头的个数 明显的线段树区间合并,记录lmax(从左端点开始的最长值) rmax(从右端点开始的最长值) 用于更新mmax(区间最长值)  但是这儿有区间更新,所以记录0的三个最长值和1的三个最长值,更新父节点的时候交换0与1就好.  还有这儿注意查询时,可能值在查询的几个子区间的的相邻处(因为我们只能查…
开始懵逼找不到解法,看了网上大牛们的题解才发现是区间合并...  给你n个数形成一个数列环,然后每次进行一个点的修改,并输出这个数列的最大区间和(注意是环,并且区间最大只有n-1个数) 其实只需要维护:最大区间的值 mmax,最小区间的值 mmin.当然要维护这两个值就需要维护:左端点开始的最大与最小区间的值,右端点开始的最大与最小区间的值.然后是数列的总和,数列的最大值,最小值.然后就是查询时的区间最大值等于整个区间的mmax和区间和sum减去mmin,但是当都是非负数,都是负数时要特判.亏我…
Hotel Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever th…