2012年8月29日
摘要: 仍然是询问区间最大连续和,只不过多了插入和删除操作。线段树搞不定了。。伸展树来了。插入删除偷懒那样写了,加了读入优化卡过的。 1 #include<cstdio> 2 #include<iostream> 3 #define MAX(a,b) ((a)>(b)?(a):(b)) 4 #define oo 1000000000 5 #define MAXN 200010 6 using namespace std; 7 int n, a[MAXN]; 8 struct SplayTree { 9 int root, size; 10 int next[MAXN].. 阅读全文
posted @ 2012-08-29 15:27 DrunBee 阅读(426) 评论(0) 推荐(0)
摘要: 操作:给出x属于[x1,y1],y属于[x2,y2],求[x,y]的最大连续和。将区间分3段考虑,答案可能由某一段的最大连续和,或者某一段往左的最大连续和,某一段往右的最大连续和组合而来。需要特判的是,区间可能存在包含关系。 1 #include<cstdio> 2 #define MAX(a,b) ((a)>(b)?(a):(b)) 3 #define MAXN 10010 4 #define oo 987654321 5 struct node { 6 int left, right, sum, val; 7 void Init() { 8 ... 阅读全文
posted @ 2012-08-29 12:28 DrunBee 阅读(337) 评论(0) 推荐(0)
摘要: 操作:1,把[x,y]每个数k变成sqrt(k),向下取整。2,查询区间的和。就算10^18,sqrt后减少的很快。当一个数为0或1时,它不会再变化了,把不会变化的区间标记,不再访问。所以暴力更新总的可以视为O(nlogn)的。 1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #define EPS 1e-8 5 #define MAXN 100010 6 typedef long long LL; 7 using namespace std; 8 struct node { 9 LL 阅读全文
posted @ 2012-08-29 09:53 DrunBee 阅读(262) 评论(0) 推荐(0)
摘要: 操作:1,更新某个位置的值。2,查询区间最大连续和。更新位置然后PushUp。查询同【SPOJ】1043 Can you answer these queries I。 1 #include<cstdio> 2 #define MAX(a,b) ((a)>(b)?(a):(b)) 3 #define MAXN 50010 4 #define oo 1000000000 5 struct node { 6 int left, right, sum, val; 7 void Init() { 8 sum = 0; 9 left = right = v... 阅读全文
posted @ 2012-08-29 00:16 DrunBee 阅读(340) 评论(0) 推荐(0)
摘要: 操作:查询区间最大连续和。每个节点保存当前区间往左,往右的最大和。往左最大连续和=max(左区间往左最大连续和,左区间的和+右区间往左最大连续和)。区间最大值=max(左,右区间最大值,左区间右连续+右区间左连续)。返回答案时,区间需要不断的合并。 1 #include<cstdio> 2 #define MAX(a,b) ((a)>(b)?(a):(b)) 3 #define MAXN 50010 4 #define oo 1000000000 5 struct node { 6 int left, right, sum, val; 7 void Init() { 8 .. 阅读全文
posted @ 2012-08-29 00:08 DrunBee 阅读(387) 评论(0) 推荐(0)