POJ-2352.Stats(树状数组简单应用)
Stars
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 58255 | Accepted: 24860 |
Description

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
You are to write a program that will count the amounts of the stars of each level on a given map.
Input
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
Hint
Source
/*
读题很容易知道,每一颗star i 只需要那些满足 j.time < i.time and j.row <= i.row的star即可,依题意我们知道这刚好就是输入顺序。
so 我们只需要选择那些在某个star之前放的并且row小于等于他的star。
所以我们可以把i.row插入,即可查出在某个数j插入之前row.i < row.j的数量
*/
#include <cstdio>
using namespace std; const int maxn = 32000 + 5;
int n, c[maxn], ans[maxn]; int lowbit(int x) {
return x & (-x);
} void add(int x, int d) {
while(x <= maxn) {
c[x] += d;
x += lowbit(x);
}
} int query(int x) {
int sum = 0;
while(x > 0) {
sum += c[x];
x -= lowbit(x);
}
return sum;
} int main() {
int x, y;
scanf("%d", &n);
for(int i = 0; i < n; i ++) {
scanf("%d %d", &x, &y);
x += 1;
ans[query(x)] ++;
add(x, 1);
}
for(int i = 0; i < n; i ++) {
printf("%d\n", ans[i]);
}
return 0;
}
POJ-2352.Stats(树状数组简单应用)的更多相关文章
- POJ 2352 【树状数组】
题意: 给了很多星星的坐标,星星的特征值是不比他自己本身高而且不在它右边的星星数. 给定的输入数据是按照y升序排序的,y相同的情况下按照x排列,x和y都是介于0和32000之间的整数.每个坐标最多有一 ...
- poj 2229 Ultra-QuickSort(树状数组求逆序数)
题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- poj 2155 Matrix (树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16797 Accepted: 6312 Descripti ...
- POJ 2155 Matrix[树状数组+差分]
原题链接:https://vjudge.net/problem/POJ-2155 题目大意 给定 n* n 矩阵A,其元素为0或1. A [i][j] 表示第i行和第j列中的数字.最初全为0. 我们有 ...
- POJ 2155 Matrix (树状数组 && 区间计数)
题意 : 给出一个N*N的矩阵, 矩阵只有可能包含0或1, 一开始则全部是0.对于矩阵可以进行两种操作, 第一种是输入 C x1 y1 x2 y2 表示, 对以(x1, y1)为左上角, 以(x2, ...
- poj 3067 - Japan(树状数组)
先按第一个数从大到小排序,相等的情况下,第二个数按照从大到小排序..... 预处理后,照着树状数组写就行了... 注意:k的最大值应取1000*1000 代码如下: include <cstdi ...
- poj 2481 - Cows(树状数组)
看的人家的思路,没有理解清楚,,, 结果一直改一直交,,wa了4次才交上,,, 注意: 为了使用树状数组,我们要按照e从大到小排序.但s要从小到大.(我开始的时候错在这里了) 代码如下: #inclu ...
- POJ 1990 MooFest --树状数组
题意:牛的听力为v,两头牛i,j之间交流,需要max(v[i],v[j])*dist(i,j)的音量.求所有两两头牛交谈时音量总和∑(max(v[i],v[j])*abs(x[j]-x[i])) ,x ...
随机推荐
- iptables常用语法与案例
常用命令语法: [root@www ~]# iptables [-t tables] [-L] [-nv] 选项与参数: -t :后面接 table ,例如 nat 或 filter ,若省略此项目, ...
- Python---进阶---logging---装饰器打印日志2
### logging - logging.debug - logging.info - logging.warning - logging.error - logging.critical ---- ...
- java -jar 和 java -cp 区别
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12022527.html Project Directory SRC MainTest.java pac ...
- Centos 6.4 x86_64 最小化安装后的优化——还需要整理
Centos 6.4 x86_64 最小化安装后的优化 购买了服务器以后要做的第一件事就是安装操作系统了,这里推荐安装 Centos 6.4 x86_64,安装系统时要选择最小化安装(不需要图 ...
- React native 平时积累笔记
常用插件: react-native-check-box 复选框react-native-sortable-listview 列表拖拽排序 react-native-doc-viewer 预览组件 r ...
- PHP实现大文件上传和下载
一提到大文件上传,首先想到的是啥??? 没错,就是修改php.ini文件里的上传限制,那就是upload_max_filesize.修改成合适参数我们就可以进行愉快的上传文件了.当然啦,这是一般情况下 ...
- Leetcode 14. Longest Common Prefix(水)
14. Longest Common Prefix Easy Write a function to find the longest common prefix string amongst an ...
- 学习日记16、easyui editor datagrid 动态绑定url
首先获取easyui当前的editor,然后看代码就可以了 var Index = $("#draw").datagrid("appendRow", { Ext ...
- Oracle--SQL程序优化案例一
下面是存储过程的一部分程序: PROCEDURE SAP_MAN_ROUTING_SO (CITEM_ID VARCHAR2, C ...
- 在 mac 系统上安装 python 的 MySQLdb 模块
在 mac 系统上安装 python 的 MySQLdb 模块 特别说明:本文主要参考了Mac系统怎么安装MySQLdb(MySQL-Python) 第 1 步:下载 MySQL-python-1.2 ...