![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构-线段树
文章平均质量分 80
___Evan
这个作者很懒,什么都没留下…
展开
-
FAFU-1272 官渡 线段树成段更新
http://acm.fafu.edu.cn/problem.php?id=1272#include "stdio.h"const int maxn = 100050;int data[maxn],n,q,max,min,x,y;struct node{ int max,min; node() { max = -1<<30; min = 1<<3原创 2013-10-17 18:17:24 · 542 阅读 · 0 评论 -
POJ-2886 Who Gets the Most Candies? 线段树 + 反素数
题目链接#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 500100;const int inf = 1<<30;//0x7f;int n,k;char name[maxn][11]; i原创 2014-03-30 19:07:19 · 417 阅读 · 0 评论 -
POJ-2528 Mayor's posters 线段树+离散
题目链接题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报思路:这题数据范围很大,直接搞超时+超内存,需要离散化:离散化简单的来说就是只取我们需要的值来用,比如说区间[1000,2000],[1990,2012] 我们用不到[-∞,999][1001,1989][1991,1999][2001,2011][2013,+∞]这些值,所以我只需要1000,1990,2000,20原创 2014-04-01 14:29:52 · 388 阅读 · 0 评论 -
HDU-4288 Coder 线段树
题目链接题目大意:给你一个有序集合,进行插入,删除,求所有下标摸为3的数和;#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 100005;const int inf = 1<<原创 2014-03-27 18:10:29 · 472 阅读 · 0 评论 -
FAFU-1398 面积 矩形面积并 线段树+扫描线
题目链接HDU1255加强版#include "stdio.h"#include "algorithm"using namespace std;const int maxn = 2110;int n;double y[maxn];struct node{ double x,y1,y2; //x 边的位置 y边的区间大小 int f;原创 2014-04-02 19:15:41 · 406 阅读 · 0 评论 -
POJ-2828 Buy Tickets 线段树
题意:人们一个一个的来排队并插队,按人到来的顺序给出每个人插队的位置(插在第几个人后面),并告知每个人的id号,输出最终队伍的情况。分析:可以用线段树,从最后来的一个人开始向来得更早的人遍历,这样pos(插在第几个人后面)的意义就变成了,前面有多少个空位。线段树上每个节点中存储的是当前时刻,该区间有多少空位。#include#include#includ原创 2014-03-25 16:42:07 · 308 阅读 · 0 评论 -
HDU-4521 小明序列 线段树+DP
题目链接LIS解法#include #include #include using namespace std;const int maxn = 100005;const int inf = 1<<30;int n,k;int a[maxn],dp[maxn],c[maxn];//a数组存放序列//dp记录在i点时最长的递增子序列长度//c数组为原创 2014-03-30 21:16:34 · 403 阅读 · 0 评论 -
hdu-4578 Transformation 线段树成段更新
题意:有一个序列,有四种操作:1:区间[l,r]内的数全部加c。2:区间[l,r]内的数全部乘c。3:区间[l,r]内的数全部初始为c。4:询问区间[l,r]内所有数的P次方之和。#include "stdio.h"#include "string.h"#include "queue"#include "vector"#include "algo原创 2014-07-19 14:43:12 · 411 阅读 · 0 评论 -
hdu-4614 Vases and Flowers 成段更新
#include "stdio.h"#include "string.h"#include "queue"#include "vector"#include "algorithm"using namespace std;const int maxn = 50005;const int mod = 10007;const int inf = 1<<30;int n,m;int o原创 2014-07-19 17:12:31 · 375 阅读 · 0 评论 -
Uva 11402 Ahoy, Pirates! 线段树成段更新
#include #include #include #include #include using namespace std;typedef long long LL;const int maxn = 1024005;const int Mod = 1000000007;int n,op,x,y;char str[maxn];int p[maxn],temp[maxn];原创 2014-07-13 21:14:41 · 459 阅读 · 0 评论 -
HDU-3225 Help with Intervals 线段树成段更新
题目链接题意:区间操作,交,并,补等思路:我们一个一个操作来分析:(用0和1表示是否包含区间,-1表示该区间内既有包含又有不包含)U:把区间[l,r]覆盖成1I:把[-∞,l)(r,∞]覆盖成0D:把区间[l,r]覆盖成0C:把[-∞,l)(r,∞]覆盖成0 , 且[l,r]区间0/1互换S:[l,r]区间0/1互换成段覆盖的操作很简单,比较特殊的就是区间0/1原创 2014-03-29 20:20:03 · 464 阅读 · 0 评论 -
HDU-3667 Hetol 线段树 区间合并
题目链接题目大意:一共有n个房间,初始全为空,会有两种操作,一种是询问是否有r个连续的房间,若有,则将最左端有r个连续的房间全部入住,若没有则输出0,另一种是将从u开始的d个位置退房。#include#include#include#include#include#include#include#include#includeusing names原创 2014-03-28 20:56:18 · 435 阅读 · 0 评论 -
HDU-2795 Billboard 线段树单点更新
题目链接#include "stdio.h"const int maxn = 200005;int tree[maxn*3];int v,w,ans;int Min( int a,int b ){ return a<b?a:b;}void buildtree( int ld,int rd,int t ){ tree[t] = 0; if( ld原创 2014-03-28 22:12:04 · 331 阅读 · 0 评论 -
HDU-1166 敌兵布阵 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1166 #include "stdio.h"#include "string.h"const int maxn = 50005;int a[maxn],tree[maxn*4];int n;void Pushup( int t ){ tree[t] = tree[t*2]原创 2013-10-27 19:57:30 · 554 阅读 · 0 评论 -
FAFU-1008 魔棍 线段树成断更新
http://acm.fafu.edu.cn/problem.php?id=1008#include "stdio.h"const int Max=100005;int x,y,v;int tree[4*Max+1];void creat( int l,int r,int t ) //创建结点{ tree[t]=10; if( l==r ) return;原创 2013-10-17 18:15:04 · 695 阅读 · 0 评论 -
HDU-1264 Counting Squares 矩形面积并 线段树+扫描线
题意: 给任意个矩形求矩形的并集 交集算的面积为覆盖一次或一次以上的面积 并集为覆盖两次或两次以上的面积 代码就多个求覆盖两次或两次的函数 可以参考矩形面积交http://blog.csdn.net/u011742541/article/details/13233973 #include "stdio.h"#include "algorithm"us原创 2013-10-28 18:42:13 · 1049 阅读 · 1 评论 -
HDU-1754 I Hate It 线段树
#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;const int maxn = 200005;const int inf = 1<<30;int n,m;int x,y,ad,ans;struct node{ int score;}tree[max原创 2013-10-29 12:50:45 · 494 阅读 · 0 评论 -
面积
#include "stdio.h"#include "algorithm"using namespace std;const int maxn = 2010;int n;double y[maxn];struct node{ double x,y1,y2; //x 边的位置 y边的区间大小 int f; //f 标记 前边还是原创 2013-11-23 11:11:43 · 478 阅读 · 0 评论 -
HDU-1255 覆盖的面积 线段树 + 扫描线
求矩形面积交 主要是扫描线不太懂 纠结了很久 #include "stdio.h"#include "algorithm"using namespace std;const int maxn = 2010;int n;double y[maxn];struct node{ double x,y1,y2; //x 边的位置 y边的区间大小原创 2013-10-27 20:08:24 · 1434 阅读 · 0 评论 -
HDU-1698 Just a Hook 线段树成段更新
题目链接#include "stdio.h"const int maxn = 100050;int n,x,y,z;struct Node{ int val;}tree[maxn*4];void pushup( int t ){ tree[t].val = tree[t*2].val + tree[t*2+1].val;}void pushdown(原创 2014-03-28 14:08:21 · 489 阅读 · 0 评论 -
HDU-1540 Tunnel Warfare 线段树 区间合并
http://acm.hdu.edu.cn/showproblem.php?pid=1540题意: 给出直线上一系列的村庄,如果相邻村庄都没有被破坏, 则两村庄是连接的,题目给出一系列的破坏操作,对指定号码的村庄进行破坏, 还有一系列的询问操作,询问与指定号码的村庄直接相连或间接相连的村庄有几个, 还有一个修复操作,是对最后破坏的村庄进行修复。 //线段树定义三原创 2013-10-17 18:20:36 · 800 阅读 · 0 评论 -
HDU-1542 Atlantis 矩形面积并 扫描线
和hdu1255、hdu1264 一个类型 就不多做解释 详见:1255 http://blog.csdn.net/u011742541/article/details/132982371264 http://blog.csdn.net/u011742541/article/details/13233973 #include "stdio.h"#include "a原创 2013-10-28 18:47:35 · 489 阅读 · 0 评论 -
poj-3368 Frequent values 线段树
题目链接#include "stdio.h"#include "math.h"#include "string.h"#include "algorithm"using namespace std;const int maxn = 100005;int n,m,x,y,ans;int num[maxn];struct node{ int mmax,lmax,rmax;原创 2014-08-10 21:25:29 · 365 阅读 · 0 评论