线段树
syyyyyw
acmer一枚
展开
-
poj 3468(线段树区间修改合并)
题目链接 当时做的时候不会延时标记 就GG了 通过这道题,大大地增加了对数据结构的理解 #include #include #include using namespace std; const int maxn=100005; struct Node { int l,r; long long value; long long tag; }Segtree[maxn*4]; int a[原创 2017-04-23 17:28:32 · 209 阅读 · 0 评论 -
hdu 6356 杭电多校第5场1007
线段树维护最小值 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int maxn=1e5+10; int mi[maxn*4]; int t,n,m,X,Y,V; unsigned...原创 2018-08-06 18:34:49 · 210 阅读 · 0 评论 -
hdu 3974
这题的关键在于dfs建序 这样2 对应的区间就是1-5 3对应的区间就是2-4 4对应的区间就是3-3 1对应的区间就是4-4 5对应的区间就是5-5 剩下的就是区间修改 单点查询了 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algor...原创 2018-08-01 22:45:24 · 169 阅读 · 0 评论 -
hdu 1540
写的时候一直没发现有一个问题 看了一遍kuangbin的代码,自己以为理解了,手写了一边,wa了 找了半天才发现 Query(o<<1|1,mid+1,r,mid+1) 不是Query(o<<1|1,mid+1,r) 位置是x 我选择x的话,会一直递归左子树 答案就是变成2了 实际答案是3 第一份代码 #include<cstdio>...原创 2018-08-01 21:32:01 · 167 阅读 · 0 评论 -
hdu 4366
用dfs转化为区间 用线段树维护忠诚度 对能力进行排序 大的优先 因为题目要求忠诚度最高且能力比他大 先建大的,再建小的,小的就被push_up了 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<vect...原创 2018-08-06 17:39:31 · 182 阅读 · 0 评论 -
hdu 4027
点更新,区间查询 点最多更新7次,若r-l+1==sum[o],直接返回 这个题的坑真多 一开始一直超时 换成Long long 就不超时 ??? 不应该Wa吗 不对,应该直接溢出,变成负数了,就取根号没效果了,就超时了。。 每个样例要有换行 最后x,y的大小不固定,要注意这一点 #include<cstdio> #include<iostream> #...原创 2018-07-31 22:43:37 · 160 阅读 · 0 评论 -
hdu 6273
第一次写想用维护gcd 后来一想发现了bug 3^3 3^3 3 维护完是1 而结果是3 就用线段树维护最小2和3的最小数量 然后快速幂求 但wa了好多次 原因在于lazy[o<<1]+=lazy[o]; lazy[o<<1|1]+=lazy[o] 不是直接赋值 自己对线段树的理解还不够 代码如下 #include<cstdio> #...原创 2018-07-31 19:29:56 · 251 阅读 · 0 评论 -
poj 3264
代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int a[50005]; int b[50005*4],c[50005*4]; int mi,ma; int x,y; void Build(in...原创 2018-07-31 16:35:27 · 123 阅读 · 0 评论 -
ZOJ 1610
坑是看是否相同 解决后还是不对 如果sum[o]>=0直接判断,就是wa 看别人写到l==r 就是对的 不知道为什么 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int x,y...原创 2018-07-31 16:20:39 · 270 阅读 · 0 评论 -
poj 2528
离散化加线段树 学习了离散化的方法 对不同颜色的记录 一开始查询不知道什么时候返回,甚至还判断lazy=-1写麻烦了 其实只需要l==r就可以返回了 还有那种特殊的情况,要加1 代码如下 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> ...原创 2018-07-31 11:34:15 · 390 阅读 · 0 评论 -
upc 5725 小奇画画
一开始用点做的,1-2 3-4 push_up后把1-4合并,这样是不对的 用边做是对的, 但超时了,跑了1100ms 看别人的代码 发现自己用的map过多 改了改,跑了700ms 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm>...原创 2018-07-30 11:55:45 · 111 阅读 · 0 评论 -
hdu 1698
带延时标记的线段树 代码如下 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; const int maxn=100005; int sum[maxn*4]; int lazy[maxn*4]; int ...原创 2018-07-30 08:41:54 · 297 阅读 · 0 评论 -
hdu 1166
练练手,代码如下: #include<cstdio> #include<algorithm> #include<cstring> #include<algorithm> using namespace std; const int maxn=50005; int a[maxn]; int sum[maxn*4],x,y; void Build(i...原创 2018-07-29 16:29:00 · 75 阅读 · 0 评论 -
hdu 1754
单点修改,区间查询 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int maxn=200005; int a[maxn]; int ma[maxn*4]; char s; int A,B; ...原创 2018-07-29 16:04:04 · 93 阅读 · 0 评论 -
ACM-ICPC 2018 南京赛区网络预赛 G
用线段树维护满足条件序号最小的那个 代码如下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int maxn=1e5+7; const int inf=1e9; int ans1[maxn]...原创 2018-09-05 11:06:01 · 119 阅读 · 0 评论