
线段树
文章平均质量分 77
yun_weiguo
这个作者很懒,什么都没留下…
展开
-
poj 3468
A Simple Problem with Integers一直在数据类型上出错。终于知道long long 是 “%lld” 来输出输入了。time 1732ms#include #include #define LL long longusing namespace std;const int N=100005;LL add[N<<2];LL sum[N<<2];v原创 2015-02-25 15:20:19 · 291 阅读 · 0 评论 -
poj 2823(线段树)
我用的是朴树的线段树。没有经过优化的。用了9K+ms ,第一次看到这么大的时间。不知道lazy 该怎么标记。 本来想试一试zkw线段树的,但是不是很熟,写不出来因为要求最大最小值,一开始我只用了一个query 想同时 得到最大最小,最后发现实现不了。用了两个函数,一个求最大,一个求最小。得出来了。#include #include #include #incl原创 2015-02-26 19:27:00 · 452 阅读 · 0 评论 -
hdu 1754(线段树)
做了hdu 1166 后,这道题目只要稍稍修改一下就可以了。 不过在一直卡在一个小bug 里面, 花了好长的时间 #include #include using namespace std;const int N=20005;int Max[N<<2];int max(int a,int b){return a>b?a:b ;}void push_up(in原创 2015-02-24 15:20:29 · 397 阅读 · 0 评论 -
Hdu 1498(线段树)
Just a Hook这是一道延迟标记的题目,刚入门,还不是特别了解。但是 push_down 函数很重要,mark 以后再好好思考思考#include #include using namespace std;const int N=100005;struct node{ int col,sum;}tree[N<<2];void原创 2015-02-24 22:45:28 · 296 阅读 · 0 评论 -
hud 1166
线段树做法#include #include #include using namespace std;const int N=50005;int ans;struct node { int l,r,sum; int mid() { return (l+r)>>1 ; }}tree[N*4];void build(int l,int r,int rt){原创 2015-02-24 11:53:44 · 381 阅读 · 0 评论 -
hdu 1394(线段树)
time 62ms#include #include #include using namespace std;const int N=5005;int sum[N<<2];int a[N];void push_up(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1] ; }void build(int l,int r,int rt){原创 2015-02-24 20:59:09 · 341 阅读 · 0 评论 -
树状数组模板+ poj 1195
模板模板int lowbit(int x){ return x & (-x);}void modify(int x,int add)//一维{ while(x<=MAXN) { a[x]+=add; x+=lowbit(x); }}int get_sum(int x){原创 2015-02-27 09:51:12 · 384 阅读 · 0 评论 -
2182(线段树)
Lost Cowssegment tree is so amaing !!!#include #include #define N 8005int T[N<<2];int a[N];int b[N];void push_up(int rt){ T[rt]=T[rt<<1]+T[rt<<1|1] ; }void build(int l,int原创 2015-02-27 17:48:04 · 361 阅读 · 0 评论 -
poj 2828(线段树)
//题目的关键就在于查询元素所在的位置int query(int l,int r,int rt,int p){ if(l==r) { sum[rt]=0; return l; } int ret; int m=(l+r)>>1; if(p<sum[rt<<1]) //与2182 相类似,不过这里只有< 不是<=。原创 2015-02-28 11:58:10 · 500 阅读 · 0 评论