随笔分类 -  DATA STRUCT

ZOJ Monthly, March 2013 - A A Simple Tree Problem
摘要:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=4959题意:给一棵树,树的每个节点初始值为0,要求支持两种操作:o k : 将k下的子树值取反q k : 查询k下的子树值有多少个为1思路:化树结构为线性,每个点管理一个区间。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using name 阅读全文

posted @ 2013-03-31 17:12 aigoruan 阅读(441) 评论(0) 推荐(1)

uva 12501 - Bulky process of bulk reduction
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3945题意:给一个序列,有两种操作:1、query i j : a[i]*1+a[i+1]*2+a[i+2]*3+....+a[j]*(j+1)的值。2、change i j u:把区间[i,j]的值都加上u。思路:用线段树维护两个值s1,s2:s1为当前区间[l,r]的a[l]*1+a[l+1]*2+a[l+2]*3+....+a[r]*(r+1)的值。s2为当前区间[l,r]的 阅读全文

posted @ 2012-10-07 12:13 aigoruan 阅读(264) 评论(0) 推荐(0)

uva 10273 - Eat or Not to Eat?
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1214&mosmsg=Submission+received+with+ID+10683084题意:农场有n头奶牛,每头奶牛都有一个产奶周期ti天(ti<=10),每天产奶ai,每天农场都想杀一头奶牛吃,但希望杀产奶最小的一头,如果有多头产奶最小,则那天将不杀。现问最后剩下几头,杀最后一头牛是第几天。思路:n头牛产奶周期的最小公倍数G一定小 阅读全文

posted @ 2012-10-04 10:54 aigoruan 阅读(239) 评论(0) 推荐(0)

Can you answer these queries V gss5
摘要:在gss3的基础上再YY一下吧~~~http://www.spoj.pl/problems/GSS5/View Code #include<stdio.h>#include<string.h>#include<iostream>#define lson rt<<1#define rson rt<<1|1using namespace std;const int maxn = 10005;int sum[maxn],bs[maxn];int n,m;struct nd{ int sum,lx,rx,mx;}as[maxn<< 阅读全文

posted @ 2012-09-30 11:29 aigoruan 阅读(178) 评论(0) 推荐(0)

spoj 2713 Can you answer these queries IV
摘要:http://www.spoj.pl/problems/GSS4/题意:给一个数列,有两个操作:0 L,R,把区间[L,R]内的数开平方。1 L,R,求区间[L,R]的和。思路:因为一个1e18的数开方8次后必为1,所以时间复杂度为O(8*n+n*log(n))。View Code #include<stdio.h>#include<string.h>#include<iostream>#include<math.h>#define LL long long#define lson rt<<1#define rson rt<&l 阅读全文

posted @ 2012-09-29 21:09 aigoruan 阅读(281) 评论(0) 推荐(0)

Can you answer these queries III
摘要:http://www.spoj.pl/problems/GSS3/题意:求区间的最大连续序列和,带修改。思路:和GSS1差不多,多一个更新而已。View Code #include<stdio.h>#include<string.h>#include<iostream>#define lson rt<<1#define rson rt<<1|1#define LL long longusing namespace std;const LL maxn = 50005;LL bs[maxn],n,m;struct nd{ LL lx,rx 阅读全文

posted @ 2012-09-29 18:14 aigoruan 阅读(185) 评论(0) 推荐(0)

2012 ACM/ICPC Asia Regional Hangzhou Online Super Mario hdu 4417
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4417思路:线段树+二分裸奔~~~View Code #include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;const int maxn = 100005;int as[23][maxn*4];int n,m;void build(int rt,int l,int r,int d){ int md=(l+r)>>1; fo 阅读全文

posted @ 2012-09-23 18:11 aigoruan 阅读(343) 评论(5) 推荐(0)

uva Permutation Transformer
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3073题意:原始序列为1,2,3,4,,,,n;现有操作:L,R将区间[L,R]割下来,反序后放到序列的最后。思路:splay暴力splay很容易完成区间切割,区间插入。 阅读全文

posted @ 2012-09-18 10:43 aigoruan 阅读(124) 评论(0) 推荐(0)

SPOJ 1043 Can you answer these queries I(GSS1 线段树)
摘要:http://www.spoj.pl/problems/GSS1/题意:给一个序列,求区间的最大连续子序列和。思路:维护三个值区间的最大连续和,左端连续的最大和。右端连续的最大连续和。查询的时候先看左右两个区间的最大连续和,再看两区间交界处的最大连续和。(参考:http://blog.csdn.net/acm_cxlove/article/details/7982444)View Code #include<stdio.h>#include<string.h>#include<iostream>using namespace std;const int ma 阅读全文

posted @ 2012-09-17 14:04 aigoruan 阅读(161) 评论(0) 推荐(0)

uva Array Transformer
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3154题意:给一个序列,然后是操作:L,R,V,P:求区间[L,R]中小于V的个数k,然后更新 P位置的值为k*u/(R-L+1)。输出最后的序列。思路:线段树 套 sbt.View Code #include<stdio.h>#include<string.h>#include<iostream>#include<stdlib.h> 阅读全文

posted @ 2012-09-17 13:06 aigoruan 阅读(177) 评论(0) 推荐(0)

2012 ACM/ICPC Asia Regional Changchun Online A Simple Problem with Integers
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4267思路:树状数组更新。View Code #include<stdio.h>#include<string.h>#include<iostream>#define lowbit(x) (x)&(-x)using namespace std;const int maxn = 50005;int sum[maxn][11][11],n;int as[maxn];void add(int x,int c,int k,int md){ for(; x <= n; 阅读全文

posted @ 2012-09-08 20:10 aigoruan 阅读(141) 评论(0) 推荐(0)

2012 ACM/ICPC Asia Regional Changchun Online Alice and Bob
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4268思路:贪心+树状数组。把两个人的x,y按x优先排序,然后离散化。然后从alice的最小x开始枚举,把bob的所有的Xb<=Xa的Yb都放到一个堆里。然后在堆里找一个最大的Yb,使得Yb<=Ya,找到则删除。(可以转化树状数组找第k大哈)View Code #include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#define lowbit(x) (x)&am 阅读全文

posted @ 2012-09-08 18:15 aigoruan 阅读(290) 评论(0) 推荐(0)

uva 11990 - ``Dynamic'' Inversion
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141题意:给一个N的排列。有M个操作,每次把排列中的一个数删除,问把这个数删除前总的逆序数是多少。思路:线段树+树状数组(也就是是树套树)。建树时,要把各区间内的数排好序。线段树中每个节点维护一个树状数组,记录这个区间有多少个数已删除。查找时,二分这个数在这个区间上的位置,然后算出小于它的有多少个,大于他的有多少个,再用树状数组去除删除的。更新时,二分这个数在这个区间的位置,更新 阅读全文

posted @ 2012-09-01 10:53 aigoruan 阅读(785) 评论(0) 推荐(0)

ZOJ Monthly, August 2012 3643 Keep Deleting
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3643题意:给出A串和B串,删除B串中的A串。思路:栈+暴力,strcmp函数比较的时候,如果不相等就会马上退出,这样最坏的时间复杂度是O(maxn/256*(1+256)*256/2)。ps:不知道官方解题是怎么样弄的。View Code #include<stdio.h>#include<string.h>#define maxn 512005char as[maxn],bs[2000],st[maxn];int ans,tp;int main 阅读全文

posted @ 2012-08-26 21:41 aigoruan 阅读(196) 评论(0) 推荐(0)

ZOJ Monthly, August 2012 3641 Information Sharing
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3641题意:有三种操作:1)arriveNamema1a2..am:名字为Name的人到达,带有m个信息:a1a2..am(m<=10)2)shareName1Name2:Name1和Name2共享信息(注意是一直共享的)3)checkName:检查Name拥有的信息,并要求输出。信息最多1000个,现有n个这些操作。思路:并差集,将共享信息的人弄成一个连通分量,并合并信息。View Code #include<stdio.h>#include<s 阅读全文

posted @ 2012-08-26 21:38 aigoruan 阅读(191) 评论(0) 推荐(0)

ZOJ Monthly, August 2012 3635 Cinema in Akiba
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3635题意:先给一个数列1、2、3……n。然后求第k小,并将它删除。思路:树状数组+二分 模板View Code #include<stdio.h>#include<string.h>#include<iostream>#define lowbit(x) (x)&(-x)using namespace std;const int maxn = 100005;int n,sum[1<<20];int as[maxn]; 阅读全文

posted @ 2012-08-26 21:36 aigoruan 阅读(211) 评论(0) 推荐(0)

ZOJ Monthly, August 2012 3633 Alice's present
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3633题意:给一个数列,每次询问一个区间第一次出现两次的位置(从右向左)。思路:开一个数组,记录当前值的左边第一次出现的位置。然后用线段树维护这个数组的区间最大值就行了。View Code #include<stdio.h>#include<string.h>#include<map>#include<utility>#include<algorithm>using namespace std;const int 阅读全文

posted @ 2012-08-26 21:32 aigoruan 阅读(210) 评论(0) 推荐(0)

hdu 4339 Query
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4339题意:给两串字符串,有两个操作:1) 1 a i c - 将第a串的第i个字符修改成c;2) 2 i - 求两个串从第i位置开始的最长相同长度。思路:因为答案只和当前位置前面的有关,所以可以用树状数组。具体如下:如果第i个位置上相同,则为0,不同则为1,这样就可以转化成求第i个位置后面一第一个1的位置。这样用求第k大解之。(加上读入优化rank1)View Code #include<stdio.h>#include<string.h>#include<iostream&g 阅读全文

posted @ 2012-08-19 10:59 aigoruan 阅读(133) 评论(0) 推荐(0)

hdu 4366 Successor
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4366线段树题意是要找某个点其子孙中能力值其能力值的中忠诚度最大的。首先可以遍历一遍将树上每个点标记为一维区间上的某个点,且在同一棵子树内的点是连续的一段。将所有点按能力从大到小排序,能力相同的编号小的排在前面,然后扫描一遍,扫描时维护一颗线段树,先查找该点为根节点的子树内的最优值,然后插入该点的忠诚度。维护区间的最大忠诚值就行了。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 阅读全文

posted @ 2012-08-18 19:16 aigoruan 阅读(185) 评论(0) 推荐(0)

ustc 1303 Special tree
摘要:http://acm.ustc.edu.cn/ustcoj/problem.php?id=1303/*题意:给一棵树,树上每个节点都有一个值。对于一棵树,如果断开某一条边,就会形成两个连通分量。现有两种操作:Query x:如果断开第x条边,输出两个连通分量里的最大值,值小的在前面。Add x a b:如果断开第x条边形成的两个连通分量里节点的个数不相等,则节点多的连通分量里都加上max(a,b),节点少的连通分量里都加上min(a,b).思路:原题是这个吧:http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1333dfs遍历一次树,就可以得到一 阅读全文

posted @ 2012-08-15 10:57 aigoruan 阅读(181) 评论(0) 推荐(0)

导航