[POJ] 2352 Stars [线段树区间求和]】的更多相关文章

Stars Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given st…
题目链接 题意:在一个二维平面上有n个星星,每个星星的等级为x,x为该星星左方和下方所包含的星星的数量(包含正左和正下的),输出每个等级各有多少星星,星星坐标按照y序递增给出,y值相同按照x递增给出. 题解:因为已经排好序了,我们每次更新加查询就可以了,因为后加入的一定是下方或者同行的,查询一下是不是左面的就行了.可以用线段树或者树状数组做,注意建树是N不是n,区间更新问题好像可以用什么lazy标记,这道题主要考察的还是思路.注意本题是按照值来进行查询的,建树的时候要用N建树. #include…
转载自 http://www.cnblogs.com/fenshen371/archive/2013/07/25/3214927.html 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数.详细信息点击进入传送门. 思路:这个题目数据的输出顺序给了很大的便利.由于是按照纵坐标从小…
题目链接 线段树区间求和问题,维护一个最大值一个最小值即可,线段树要用C++交才能过. 注意这道题不是求三个数的最大值最小值,是求k个的. 本题数据量较大,不能用N建树,用n建树. 还有一种做法是单调队列,耗时更少. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #define N 1000005 usi…
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 区间合并 &题意: 有一个线段,从1到n,下面m个操作,操作分两个类型,以1开头的是查询操作,以2开头的是更新操作 1 w 表示在总区间内查询一个长度为w的可用区间,并且要最靠左,能找到的话返回这个区间的左端点并占用了这个区间,找不到返回0 好像n=10 , 1 3 查到的最左的长度为3的可用区间就…
https://vjudge.net/contest/66989#problem/C You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运用的时候,需要更新或查找的区间是储存在y1,y2变量里面的,值是储存在变量v里面的,查询结果储存在变量_sum里面. 每次更新(调用update函数)时,必须要维护更新区间上层的线段树,即更新节点上面的线段树表示的和是准确的和. 在update函数更新的时候,如果线段树分成区间包含于所要求的区间那么…
线段树的基本知识可以先google一下,不是很难理解 线段树功能:update:单点增减 query:区间求和 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 using namespace std; const int MAXN = 50008; int sum[MAXN<<2]; void build(int l, int r, int rt)…
给出一个n个元素的序列,序列有正数也有负数 支持3个操作: p x y 0.p=0时,把第x个的值改为y 1.p=1时,交换第x个和第y个的值 2.p=2时,问区间[x,y]里面连续k个的子序列的最大和(保证y-x+1>=k) 我们只要定义数组v v[i]表示原序列中,从第i个开始,连续k个元素的值的和 然后我们只需要维护一棵线段树,树的叶子节点表示数组v 树的节点维护: 区间[l,r]中,连续k个的子序列的最大和,即数组v的最大值 这样的话,3个操作就变为: 0.把区间[max(x-k+1,0…