POJ 2352 【树状数组】】的更多相关文章

学习自:链接以及百度百科 以及:https://www.bilibili.com/video/av18735440?from=search&seid=363548948825132979 理解树状数组 概念 假设数组a[1..n],那么查询a[1]+...+a[n]的时间是log级别的,而且是一个在线的数据结构,支持随时修改某个元素的值,复杂度也为log级别. 观察这棵树,容易发现: C1 = A1 C2 = A1 + A2 C3 = A3 C4 = A1 + A2 + A3 + A4 C5 =…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42898   Accepted: 18664 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 st…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27092   Accepted: 8033 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…
http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num[]的大小间接排序 2.bs[as[i]]=i:如今bs数组就是num[]数组的离散化后的结果 3.注意,树状数组中lowbit(i)  i是不能够为0的,0&(-0)=0,死循环... #include <cstdio> #include <cstring> #include…
题目中只n个人,每个人有一个ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛. 由于排完序之后,先插入的一定是小的,所以左右两边的大于小于都能确定,用树状数组维护选手的id Sample Input13 1 2 3Sample Output1 #include<cstdio> #include<iostream> #include<algorithm> #include<c…
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数相加 因为只有后面的数比自己笑才能交换 但是暴力求逆序数也会超时 于是用树状数组求 从最后往前看 每次求sum相加 但是数据的范围根本开不出来树状数组... 但是由于n最多只有五十万 所以把它离散化一下 把这n个数变成1~n 技巧就是先按大小排序 然后把他们变成1~n 然后按照结构体中的顺序再排回来…
Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin…
这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms. #include<iostream> #include<algorithm> using namespace std; ]; int main() { int i,j,t,n; scanf("%d",&n); mat[]=; ;i<n;i++) { scanf("%d",&t); mat[i]=t+; ;j<i;j++) if(mat[j]&g…
求逆序对最常用的方法就是树状数组了,确实,树状数组是非常优秀的一种算法.在做POJ2299时,接触到了这个算法,理解起来还是有一定难度的,那么下面我就总结一下思路: 首先:因为题目中a[i]可以到999,999,999之多,在运用树状数组操作的时候,用到的树状数组C[i]是建立在一个有点像位存储的数组的基础之上的,不是单纯的建立在输入数组之上. 比如输入一个9 1 0 5 4(最大9) 那么C[i]树状数组的建立是在: 下标 0 1 2 3 4 5 6 7 8 9 –——下标就要建立到9 数组…
Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gathering of cows from around the world. MooFest involves a variety of events including haybale stacking, fence jumping, pin the tail on the farmer, and of cours…
题目链接 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input…
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence 9 1 0 5…
Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15301   Accepted: 5095 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in hi…
Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good. Farmer John has N cows (we number the cows from 1 to N). Each of Farmer…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24954   Accepted: 7447 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascend…
痛定思痛,打算切割数据结构,于是乎直接一发BIT 树状数组能做的题目,线段树都可以解决 反之则不能,不过树状数组优势在于编码简单和速度更快 首先了解下树状数组: 树状数组是一种操作和修改时间复杂度都是O(logN)的数据结构,可以做到 单点修改前缀查询 和 区间修改单点查询 下面来看下树状数组: 由图发现 树状数组C[]对应的数组A[]中的值是这样的: C[1]=A[1] C[2]=C[1]+A[2]=A[1]+A[2] C[3]=A[3] C[4]=C[2]+A[4]=A[1]+A[2]+A[…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 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 st…
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~~~~~~ 树状数组不懂的去看刘汝佳的大白书,那个图画得非常清楚. 题目大意:星星的坐标以y递增的顺序给出,这些点的左下方的点数代表这个点的级数,问0~N-1的级数有多少个?事实上y根本木实用. 题目链接:http://poj.org/problem?id=2352 http://acm.hdu.e…
/** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and * process as 1D conditions. * @url http://poj.org/problem?id=2352 */ #include <iostream> #include <cstdio> #include <cmath> #include <…
Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4052    Accepted Submission(s): 1592 Problem Description Astronomers often examine star maps where stars are represented by points on a plan…
题意: 给了很多星星的坐标,星星的特征值是不比他自己本身高而且不在它右边的星星数. 给定的输入数据是按照y升序排序的,y相同的情况下按照x排列,x和y都是介于0和32000之间的整数.每个坐标最多有一个星星. 思路: 这题给的输入数据很祥和,间接提示思路了. 用x作为树状数组的区间,然后按照输入的顺序不断查找在包括自己的位置以及左边的星星数. 细节是x可能是0,这是树状数组不能接受的,需要对输入的x数据进行加一操作. 从这题可以看出树状数组最直白的作用就是求从1开始到某个点的某个区间的数量. #…
题意:给出n个平面二维坐标,对于每个坐标,如果这个坐标跟(0,0)形成的矩形内包含的点数为 k (包含边界,但不包含坐标本身),那么这个坐标就是 level k.输出level 0 - n-1的点数分别是多少. 思路:树状数组,线段树  稍后写一个线段树版本 #include <stdio.h> #include <string.h> #define N 15005 #define M 32005 int c[M], s[N]; int ans[N]; int n, max ,y;…
<题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数.  解题分析: 因为所有点是按照y坐标的升序优先给出,所以后面的点y坐标一定大于等于前面的.于是,判断该点前面有多少点满足在该点的“左下角”,只需看前面的点有几个x坐标小于当前点即可,所以,我们只需要对x坐标建一维树状数组即可求解. #include <cstdio> #include <cs…
题目 题意:按y递增的顺序给出n颗星星的坐标(y相等则x递增),每个星星的等级等于在它左边且在它下边(包括水平和垂直方向)的星星的数量,求出等级为0到n-1的星星分别有多少个. 因为y递增的顺序给出,于是乎这道题跟 y 无关,在每次输入x的时候都去判断比x小,即在x之前的数有多少(ans)个,即星星的等级.然后更新num[ans]++  ( 存ans等级星星的个数num[ans]++ ). 刚开始觉得x不是值吗,怎么一会又变成下标了.其实x一直都是下标,既是题中坐标系的下标,也是树状数组中的下标…
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22486 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54352   Accepted: 23386 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 st…
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 star. Astronomers wa…
总结一下树状数组的题目: {POJ}{3928}{Ping Pong} 非常好的题目,要求寻找一个数组中满足A[i]<A[k]<A[j]的个数,其中i<k<j(或者相反).很巧妙的将题目转化为树状数组的思想,从A[k]考虑,则只需要寻找左边比自己小和右边比自己大的可能性(或者相反),这样就可以用树状数组来维护.思想的转变很重要. {POJ}{1990}{MooFest} n头牛,不同的听力值v,当i,j想要通话时,需要max(v(i),v(j))*(dist[i]-dist[j])…
题目地址: http://poj.org/problem?id=2352 分析: - 题意分析:  有n个星星, 它的左下方(x和y不超过它)的星星的数目就是它的level, 分别计算level 为 0 到 n-1 的星星的数目. 输入是先按照 y 从小到大排序, 如果y相同,就按照x递增排序, 不会有2个以上星星占同一个坐标. - 数据结构 - 用原始数据数组 a 表示同一个x坐标的星星数目. (a[i]为x坐标为 i-1的星星数目).  注意输入数据时排序的. - 树状数组s维护a的信息.…