
线段树
文章平均质量分 80
ahfywff
这个作者很懒,什么都没留下…
展开
-
POJ 2886 Who Gets the Most Candies?
题意: N个孩子顺时针坐成一个圆圈且从1到N编号,每个孩子手中有一张标有非零整数的卡片。第K个孩子先出圈,如果他手中卡片上的数字A大于零,下一个出圈的是他左手边第A个孩子。否则,下一个出圈的是他右手边第(-A)个孩子。第p个出圈的孩子会得到F(p)个糖果,F(p)为p的因子数。求得到糖果数最多的是哪个孩子及得到多少糖果。 分析: 出圈过程有点类似约瑟夫环。假设当前出圈的是剩余孩原创 2012-01-31 15:17:07 · 2258 阅读 · 4 评论 -
HDU 4315 Digital root(线段树)
很不错的线段树题。#include #include #include #include using namespace std;const int maxn = 100010;int tcase, n, q;int a[maxn];/*ldr: 从区间左端点开始的前n项和的数字根的二进制表示 rdr: 从区间右端点开始的后n项和的数字根的二进制表示 idr: 区间内原创 2012-08-14 16:17:44 · 750 阅读 · 0 评论 -
HDU 4358 Boring counting(线段树)
用C++交会栈溢出,而G++不会。更新和查询我用的是线段树,1500+ms,用树状数组应该会快一些。将树形结构转换成线性结构后,等价于求指定区间内恰好出现k次的数有多少个。#include #include #include #include #include #include using namespace std;const int maxn = 100010原创 2012-08-15 00:40:18 · 2034 阅读 · 1 评论 -
HDU 4325 Flowers(线段树)
线段树的区间更新和单点查询。需要注意的是要把区间端点和查询的点都先读入并离散化。#include #include #include #include #include #include #include using namespace std;const int maxn = 100100;int tcase, n, m;int sum[maxn<<2], add[m原创 2012-08-01 20:21:05 · 997 阅读 · 4 评论 -
HDU 4366 Successor(线段树)
题意:某公司有n个人,编号从0到n-1,0号是BOSS。除BOSS外,每个人有忠诚度和能力两个属性,每个人的忠诚度都不同。每个人都有可能被BOSS炒鱿鱼,当某个人被炒后,他的所有下级中能力大于他且具有最大忠诚度的人将取代他的位置。现在给定所有人的上下级关系(下级的编号总是比上级小)和一些被炒鱿鱼的人的编号,输出取代被炒人的人的编号,如果没人取代被炒人,输出“-1”。分析:首先,把以每个节点为根原创 2012-08-19 17:51:27 · 1320 阅读 · 1 评论 -
HDU 4262 Juggler(线段树)
2012 ACM/ICPC Asia Regional Online Warmup 1006题#include #include #include #include #include using namespace std;const int maxn = 100010;int sum[maxn<<2];int pos[maxn];int n;void bui原创 2012-08-25 17:20:12 · 1000 阅读 · 0 评论 -
Codeforces#135(div.2) E.Parking lot【线段树】
E. Parking Lottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA parking lot in the City consists of n park原创 2012-08-28 23:07:34 · 1264 阅读 · 0 评论 -
HDU 3971. Play With Sequence【线段树+排序】
http://acm.hdu.edu.cn/showproblem.php?pid=3971题意:对有n(0=l且=l且解法:首先可以想到线段树,线段树的每个节点存当前区间的最大值和最小值,当然还有延迟标记。但是,如果就只是这样做,还是会TLE。由于每次更新是将>=l且#include #include #include #include #include using na原创 2012-09-26 00:13:42 · 1574 阅读 · 0 评论 -
ZOJ 3018 Population【二维线段树四分动态建树】
Population Time Limit: 10 Seconds Memory Limit: 32768 KB It is always exciting to see people settling in a new continent. As the head of the population management office, you are s原创 2012-09-13 23:37:05 · 1895 阅读 · 1 评论 -
SPOJ 3261. Race Against Time(RACETIME) 【线段树套SBT】
http://www.spoj.pl/problems/RACETIME/题意:1、修改某个数;2、求区间内小于等于某个数的数有多少个。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key,原创 2012-10-04 22:14:47 · 1752 阅读 · 0 评论 -
HDU 3954 Level up(线段树)
#include #include #include #include #include using namespace std;const int maxn = 10010;int t, n, k, qw;int need[11] = {0};int maxexp[maxn<<2][11];int add[maxn<<2];void build(int l, int原创 2012-07-22 13:26:52 · 579 阅读 · 0 评论 -
HDU 4302 Holedox Eating (线段树)
#include #include #include #include using namespace std;const int maxn = 111111;int T, L, n;int sum[maxn<<2];void build(int rt, int l, int r){ sum[rt] = 0; if (l == r) retu原创 2012-07-20 00:48:07 · 876 阅读 · 0 评论 -
HDU 4339 Query(线段树)
Problem DescriptionYou are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.Your task is to answer next queries: 1) 1 a i c - you should set i-th character in a-th string to c原创 2012-08-03 15:39:48 · 698 阅读 · 0 评论 -
hdu 3308 LCIS (线段树+单点更新+区间合并)
题意:给定n个数,然后对这n个数进行m次操作。一种操作是将第A个数替换成B,另一种操作是询问区间[a,b]是的最长连续递增子序列的长度。 分析:每个节点分别记录包括左端点的LCIS、包括右端点的LCIS和区间上的LCIS。 代码如下:#include #include #include using namespace std;const int maxn = 100原创 2012-02-04 21:13:55 · 667 阅读 · 0 评论 -
hdu 3397 Sequence operation (线段树+区间合并+双Lazy标记)
给你一个长度为n的0、1序列,然后对该序列进行m次操作(10 a b 将[a, b]上的所有数变为0;1 a b 将[a, b]上的所有数变为1;2 a b 将[a, b]上的0变成1,1变成0;3 a b 输出[a, b]上1的个数;4 a b 输出[a, b]上最长的连续的1的数目。刚开始做的时候就想用两个Lazy标记,一个覆盖标记,一个异或原创 2012-02-08 19:59:49 · 1018 阅读 · 0 评论 -
zoj3573 Under Attack (线段树)
这是ZOJ Monthly, February 2012的C题,比赛时我提交了好几次结果都是Segmentation Fault。我也不知道这是什么错误,检查了好几遍代码也没发现有什么问题。今天又重敲了一遍,提交还是SF。想了想,把数组改大了些,再提交,AC~ 但是之前数组的大小已经大于4倍区间了啊,真心不知道为什么。。。/* * ===============================原创 2012-02-26 13:12:33 · 750 阅读 · 0 评论 -
hdu1542 Atlantis (线段树+扫描线)
#include #include #include #include #include using namespace std;const int maxn = 210;double len[maxn<<2]; // 区间被覆盖的长度 int cover[maxn<<2]; // 区间被覆盖次数 double yy[maxn]; // 用于存储y坐标 ma原创 2012-03-07 23:17:34 · 1141 阅读 · 0 评论 -
HDU 3255 Farming
这题可以转化为求长方体体积的并,将每块地的价值看做高。然后求解就与上一篇差不多了。#include #include #include #include using namespace std;const int maxn = 60006;int cov[maxn<<2], len[maxn<<2];int yy[maxn];int ss[5], zz[5];map my原创 2012-03-15 13:09:29 · 664 阅读 · 0 评论 -
HDU 3642 Get The Treasury (线段树、扫描线求立方体体积交)
给定n个立方体,求这些立方体覆盖两次以上的体积。之前做过求矩形面积交的题,这题可以转化为求矩形面积交。先对y坐标和z坐标离散化,然后枚举每个z轴区间,求在该区间内矩形覆盖两次以上的面积,再乘以该区间宽度,即为该区间覆盖两次以上的体积。由于更新节点时有些地方没考虑好,TLE和WA了几次。#include #include #include #include #include #in原创 2012-03-14 17:01:55 · 1278 阅读 · 0 评论 -
HDU4027 Can you answer these queries? (线段树)
#include #include #include #include #include using namespace std;typedef __int64 LL;const int maxn = 100010;LL sum[maxn<<2];void build(int l, int r, int rt){ if (l == r) {原创 2012-04-08 22:58:52 · 553 阅读 · 0 评论 -
POJ 3368 Frequent values [Segment Tree]
给你一个非递减的序列,再给你一些区间,问你每个区间里出现次数最多的数字出现了几次。Sample Input10 3-1 -1 1 1 1 1 3 10 10 102 31 105 100Sample Output143由于所给序列是非递减的,可以把连续的相同数字看成一段连续的区间,所以本题可以转化为求区间内的最长连续子区间。#inclu原创 2012-05-22 19:04:56 · 531 阅读 · 0 评论 -
SPOJ 375. Query on a tree【树链剖分】
http://www.spoj.pl/problems/QTREE/给一颗树,每条边有一个权值。有两种操作:1、修改某条边的值;2、询问a、b两点路径上边权的最大值。树链剖分。#include #include #include #include #include #include using namespace std;const int maxn = 10010;原创 2012-09-18 21:00:39 · 1711 阅读 · 0 评论