hdu4288 Coder(段树+分离)】的更多相关文章

主题链接: huangjing 题意: 题目中给了三个操作 1:add x 就是把x插进去  2:delete x 就是把x删除 3:sum 就是求下标%5=3的元素的和. 另一个条件是插入和删除最后都要保证数列有序. .. 首先告诉一种暴力的写法. .由于时间很充足,须要对stl里面的函数有所了解. . 就是直接申明一个vector的容器.然后直接用vector里面的操作比方 insert,erase等等操作. .只是这个效率非常低.. 最后跑出来6000多ms. .(强哥的代码) 代码: #…
注意添加到集合中的数是升序的,先将数据读入,再离散化. sum[rt][i]表示此节点的区域位置对5取模为i的数的和,删除一个数则右边的数循环左移一位,添加一个数则右边数循环右移一位,相当于循环左移4位,线段树与树状数组结合,树状数组确定位置. le[rt]表示左移的位数,区间更新懒惰标记 #include <iostream> #include <cstdio> #include<cstdlib> #include<map> #include<alg…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4288 题目大意: 维护一个有序数列{An},有三种操作: 1.添加一个元素. 2.删除一个元素. 3.求数列中下标%5 = 3的值的和 解题思路: 线段树不支持动态的添加,删除操作,所以本题用了离线处理,将所有数字事先离散化,给每个数字存一个位子,然后处理. 先离线把要用到的数离散化,去重并且排序,这样做添加或删除操作的时候就可以用二分找出下表并在线段树内修改,由于是单点更新,就不用”向下传递“了…
Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u Submitcid=58236#status//B/0">Status Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing the…
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Solved: 560 [Submit][Status][Discuss] Description You have N integers, A1, A2, - , AN. You need to deal with two kinds of operations. One type of operati…
要长8000仪表板.间染色的范围,问:最后,能看到的颜色,而且颜色一共有段出现 覆盖段 数据对比水   水可太暴力 段树: #include "stdio.h" #include "string.h" struct node { int l,r,c; }data[40010]; int color[8011]; void build(int l,int r,int k) { int mid; data[k].l=l; data[k].r=r; data[k].c=-…
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9514    Accepted Submission(s): 5860 Problem Description The inversion number of a given number sequence a1, a2, ..., an…
意甲冠军:一个典型的段树C,Q问题,有n的数量a[i] (1~n),C, a, b,c在[a,b]加c Q a b 求[a,b]的和. #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<cmath> #include<iostream> #include <queue> #…
标题效果:两棵树之间的首次查询k大点的权利. 思维:树木覆盖树,事实上,它是正常的树木覆盖了持久段树. 由于使用权值段树可以寻求区间k大,然后应用到持久段树思想,间隔可以做减法.详见代码. CODE: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 100010 #define NIL (tree[0]) using names…
439-线段树的构造 II 线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间.start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 end 由 build 方法所给出. 对于节点 A 的左儿子,有 start=A.left, end=(A.left + A.right) / 2. 对于节点 A 的右儿子,有 start=(A.left + A.right) / 2 + 1, end=A.right. 如果 start 等于…