hdu 2795 线段树】的更多相关文章

注意h的范围和n的范围,纵向建立线段树 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子思路:每次找到最大值的位子,然后减去L线段树功能:query:区间求最大值的位子(直接把update的操作在query里做了)3 5 524333 1213-1 2015-05-15 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include…
Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10961    Accepted Submission(s): 4863 Problem Description At the entrance to the university, there is a huge rectangular billboard of s…
Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23498    Accepted Submission(s): 9687 Problem Description At the entrance to the university, there is a huge rectangular billboard of s…
Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18496    Accepted Submission(s): 7751 Problem Description At the entrance to the university, there is a huge rectangular billboard of s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 222222 #define lso…
h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子. 每次找能放纸条而且是最上面的位置,询问完以后可以同时更新,所以可以把update和query写在同一个函数里. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; ]; int h, w, n, qL, qR, v; void build(int o, int L, int R) { i…
#include<stdio.h> #define N 200005 int h,w,n; struct node { int x,y,max; }a]; int mmax(int e,int f) { return e>f?e:f; } void creattree(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].max=w; if(x==y) return ; int temp; int mid; creattree(temp,x,mid)…
Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 439    Accepted Submission(s): 155 Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a…
Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1647    Accepted Submission(s): 753 Problem Description There is a company that has N employees(numbered from 1 to N),every emplo…
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3348    Accepted Submission(s): 904 Problem Description Ponyo and Garfield are waiting outside the box-office for their favorite mo…
Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7502    Accepted Submission(s): 2233 Problem Description lxhgww got a sequence contains n characters which are all '0's or '1…
Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) Total Submission(s): 4095    Accepted Submission(s): 1008 Problem Description Yuanfang is puzzled with the question below:  There are n integers, a1,…
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1592    Accepted Submission(s): 444 Problem Description 因为马拉松初赛中吃鸡腿的题目让不少人抱憾而归,威威猫一直觉得愧对大家,这几天他悄悄搬到直角坐标系里去住了. 生活还要继续,太阳也照常升起,今天,威威猫在…
Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5913    Accepted Submission(s): 1380 Problem Description Memory units are numbered from 1 up to N. A sequence of memory units is c…
Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1428    Accepted Submission(s): 298 Problem Description Incredible Crazily Progressing Company (ICPC) suffered a lot with the…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10208    Accepted Submission(s): 4351 Problem Description There are several ancient Greek texts that contain descriptions of the fabled i…
Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3897    Accepted Submission(s): 1978 Problem Description A number of rectangular posters, photographs and other pictures of the same shape…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4996    Accepted Submission(s): 1576 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2482    Accepted Submission(s): 805 Problem Description Mex is a function on a set of integers, which is universally used for impartial game…
Level up Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3973    Accepted Submission(s): 1104 Problem Description Level up is the task of all online games. It's very boooooooooring. There is o…
I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 57279    Accepted Submission(s): 22365 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师…
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 66634    Accepted Submission(s): 28074 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务…
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来值开根号下的值.有两种操作,第一种就是上面描述的那种,第二种就是询问某个区间内的船的战斗值的总和. 解题思路 使用线段树就不用多说了,关键是如果不优化的话会超时,因为每次修改都是需要递归到叶子节点,很麻烦,但是我们发现,如果一个叶子节点的值已经是1的话,那个再开方它也是1,不变,这样我们就只需要判断…
敌兵布阵 HDU 1166 线段树 题意 这个题是用中文来描写的,很简单,没什么弯. 解题思路 这个题肯定就是用线段树来做了,不过当时想了一下可不可用差分来做,因为不熟练就还是用了线段树来做,几乎就是模板题了. 代码实现 #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<iostream> # define ls (rt<<…
http://acm.hdu.edu.cn/showproblem.php?pid=2795 在第一和第三多学校都出现线段树,我在比赛中并没有这样做.,热身下,然后31号之前把那两道多校的线段树都搞了,这是一道热身题 关键是建模: 首先一定看清楚题目构造的场景,看有什么特点--------会发现.假设尽量往左上放置的话.那么因为 the i-th announcement is a rectangle of size 1 * wi.,全然能够对h建立线段树.表示一行.结点里的l,r就表示从l行到…
1.HDU 1556  Color the ball   区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次只能修改一个元素的值. 这里改下思路可以用树状数组.在更新(a,b)时,向上更新,将a~n加1,b+1~n减1.查询点时,向下求和即可. #include<iostream> #include<cstr…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续0的最长长度,l1是从区间左端开始连续1的长度,r1是从区间右端开始连续1的长度,l0是从区间左端开始连续0的长度,r0是从区间右端开始连续0的长度,lazy标记该区间是否进行异或操作. 之所以要同时保存1的连续长度和0的连续长度,是因为这道题设计取反操作,所以取反是,只需将对应的0.1长度调换一下…
Problem Nice boat(HDU 4902) 题目大意 维护一个序列,两种操作. 第一种操作,将一段区间[l,r]赋值为x. 第二种操作,将一段区间[l,r]中大于等于x的数与x求gcd. 询问所有操作结束后的序列. 解题分析 用线段树开一个标记same,表示这段区间中的数是否相同,若相同则为该数,否则为-1. 对于第二种操作,对于覆盖区间内的same不为-1的子区间暴力修改. 虽然时限有15s,但貌似跑得挺快的,只用了1s,不知是数据水还是什么缘故. 参考程序 #include <c…
http://acm.hdu.edu.cn/showproblem.php?pid=1394 给出一列数组,数组里的数都是从0到n-1的,在依次把第一个数放到最后一位的过程中求最小的逆序数 线段树的应用,先建树,输入一个数,查询在在树中比他大的数的个数,然后把这个数更新进树里,再输入数重复操作,类似于进栈一样,先更新进树的数下标肯定是小于后更新的 这样只求到了一个数组的逆序数,还要有依次把第一个数放到最后的得到新数组的比较,这里有一个结论;如果是0到n的排列,那么如果把第一个数放到最后,对于这个…
http://acm.hdu.edu.cn/showproblem.php?pid=1255 典型线段树辅助扫描线,顾名思义扫描线就是相当于yy出一条直线从左到右(也可以从上到下)扫描过去,此时先将所有的横坐标和纵坐标排序 因为是从左到右扫描,那么横坐标应该离散化一下 当扫描线依次扫描的时候,依次扫描到的纵区间在线段树中查找,依据是上边还是下边记录,上边就是-1,下边就是+1, 如果某区间记录值为0的时候,代表没有被覆盖,为1的时候代表覆盖一次,为2代表覆盖两次(不会出现为负数的情况) 最后将依…