![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构:线段树
文章平均质量分 79
skajre
这个作者很懒,什么都没留下…
展开
-
POJ 3264 Balanced Lineup
// // main.cpp // Richard // // Created by 邵金杰 on 16/7/24. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include using namespace std; #define INF 10000000 const int maxn=800000+100原创 2016-07-24 21:32:37 · 157 阅读 · 0 评论 -
HDU 1166 敌兵布阵(线段树单点更新)
#include using namespace std; const int maxn=200000+5; int n,a[maxn/4]; struct Intervaltree{ int val[maxn]; void clear() {memset(val,0,sizeof(val));} void build(int o,int L,int R) {原创 2017-01-18 16:37:06 · 171 阅读 · 0 评论 -
UVA 1455 Kingdom(线段树+并查集)
因为c是小数,那么把c向上取整,区间低加一就可以了,其他的线段树维护。#include #include #include #include using namespace std; const int maxn=100000+5; struct Interval{ int sumv[5][maxn*4],addv[5][maxn*4]; void clear() {原创 2016-11-08 18:01:46 · 183 阅读 · 0 评论 -
UVA 1232 Skyline (线段树)
水题,但是被一个区间有多个高度不同的楼的判断卡了好久,之前脑子不够清晰,没想清楚,其实很简单。#include #include #include #include using namespace std; const int maxn=100000+5; int l,r,v; struct Interval{ int setv[maxn*4],minv[maxn*4]; void原创 2016-11-07 21:06:57 · 221 阅读 · 0 评论 -
UVA 12299 RMQ with Shifts(线段树)
#include #include #include #include using namespace std; const int maxn=400000+5; int l,r; struct Interval{ int minv[maxn]; void clear() {memset(minv,0,sizeof(minv));} void updata(int o,in原创 2016-11-06 23:18:05 · 229 阅读 · 0 评论 -
UVA 11992 Fast Matrix Operations(线段树+延迟标记)
这里是对区间的修改,所以需要延迟标记,否则每次修改时间复杂度将会是O(n),会超时。 #include #include #include #include using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define ss(x) scanf("%d",&x) const int maxnode=(1<<17)原创 2016-10-22 09:32:12 · 183 阅读 · 0 评论 -
UVA 1400 "Ray, Pass me the dishes!"(线段树)
训练指南上的线段树写法跟平时写的不一样,写得好难受。#include #include #include #include using namespace std; #define rep(i,a,b) for(int i=(a);i<(b);i++) #define ss(x) scanf("%d",&x) typedef long long LL; typedef pair Interval;原创 2016-10-21 20:15:05 · 165 阅读 · 0 评论 -
POJ 1177 Pictures(HDU 1828) (线段树+离散化+线段扫描)
转载来自:点击打开链接 对于这题,我们的思路步骤如下(代码和下面的文字解释结合着看): 1.对于输入的N个矩形,有2*N条纵向边,我们把这些边叫做扫描线 2.建立一个struct ScanLine,保留这些扫描线 struct ScanLine { int x;//横坐标 int y1;//扫描线的下端点 int y2;//扫描线的上端点 int flag;原创 2016-08-22 18:08:26 · 232 阅读 · 0 评论 -
POJ 1389 Area of Simple Polygons(线段树+扫描面积)
#include #include #include using namespace std; //存放纵轴的 struct line{ double x,y1,y2; bool bleft; }line[2100]; double y[2100]; struct node{ int L,R; node *pleft,*pright; int cover;原创 2016-08-22 13:59:57 · 190 阅读 · 0 评论 -
POJ 3667 Hotel(线段树+区间合并+延迟标记)
延迟标记很重要,没有延迟标记,时间复杂度还是O(n)。 // // main.cpp // Richard // // Created by 邵金杰 on 16/8/21. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include #include using namespace std; const i原创 2016-08-22 10:14:14 · 256 阅读 · 0 评论 -
POJ 1151 Atlantis
题解在注释中,每个函数都有解释。 // // main.cpp // Richard // // Created by 邵金杰 on 16/7/25. // Copyright © 2016年 邵金杰. All rights reserved. // #include #include #include using namespace std; //存放纵轴的 struct line原创 2016-07-25 20:02:34 · 310 阅读 · 0 评论 -
POJ 2528 Mayor's posters
此题处理区间时需要离散化,把海报端点作为区间的的两端,那么贴一张海报时只要看bCover就能判断该区间是否被贴满,并且贴海报时时从外往里贴的,因为先贴外面的海报,里面的不会被盖住,建树的函数不用多说,主要时贴海报的函数,如果是一张长海报,那么它就要被分解区间,如果刚好分解区间时碰到一个完整的区间,那么只要看这个区间是否被覆盖,也就是这张海报之前,这个区间是否有贴海报,也就是bCoverd为true原创 2016-07-25 09:26:23 · 176 阅读 · 0 评论 -
POJ 3468 A Simple Problem with Integers
// // main.cpp // Richard // // Created by 邵金杰 on 16/7/24. // Copyright © 2016年 邵金杰. All rights reserved. // #include const int maxn=200000+100; int nCount=0; struct CNode{ int L,R; CNod原创 2016-07-24 22:36:36 · 163 阅读 · 0 评论 -
HDU 1754 I Hate It(线段树单点更新)
#include #include using namespace std; const int maxn=800000+5; int n,m,a[maxn/4]; struct Intervaltree{ int maxx[maxn]; void clear() {memset(maxx,0,sizeof(maxx));} void build(int o,int L原创 2017-01-18 16:46:08 · 189 阅读 · 0 评论