POJ2352Stars【树状数组】
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
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
;
int C[N],cnt[N];
inline int lowbit(int x){return x&(-x);}
inline void add(int x)
{
while(x<=N)
{
C[x]++;
x+=lowbit(x);
}
return;
}
inline int count(int x)
{
;
)
{
ans+=C[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
int n,x,y;
while(~scanf("%d",&n))
{
memset(C,,sizeof(C));
memset(cnt,,sizeof(cnt));
;i<=n;i++)
{
scanf("%d%d",&x,&y);
x++;
cnt[count(x)]++;
add(x);
}
;i<n;i++) printf("%d\n",cnt[i]);
}
;
}
POJ2352Stars【树状数组】的更多相关文章
- C++-POJ2352-Stars[数据结构][树状数组]
/* 虽然题目没说,但是读入有以下特点 由于,输入是按照按照y递增,如果y相同则x递增的顺序给出的 所以,可以利用入读的时间进行降为处理 */ 于是我们就得到了一个一维的树状数组解法啦 值得一提:坐标 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
- BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1399 Solved: 694[Submit][Status] ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...
- 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组
E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- 【BZOJ-3881】Divljak AC自动机fail树 + 树链剖分+ 树状数组 + DFS序
3881: [Coci2015]Divljak Time Limit: 20 Sec Memory Limit: 768 MBSubmit: 508 Solved: 158[Submit][Sta ...
随机推荐
- stop总结
<!DOCTYPE html><html><head><meta charset="utf-8"><script src=&q ...
- 安装和配置Symfony
为了简化创建新项目的过程,Symfony提供一个安装程序. 安装Symfony Installer 使用Symfony Installer是创建新的Symfony项目的唯一推荐方式,这个install ...
- 第三章:初识Jquery
一.Jquery的优势 体积小,压缩后只有100KB左右 强大的选择器 出色的DOM封装 可靠的事件处理机制 出色的浏览器兼容性 使用隐式迭代简化编程 丰富的插件支持 二.Jquery语法 三.DOM ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)
这道直接遍历一遍求出每个点的子节点数目就行了= = CODE: #include<cstdio>#include<iostream>#include<algorithm& ...
- BZOJ 1875: [SDOI2009]HH去散步(矩阵乘法)
首先,题意就把我们引向了矩阵乘法,注意边长m<=60,那么就按边建图,变成一个120个点的图,然后乱搞就行了。 PS:WA了N久改了3次终于A了QAQ CODE: #include<cst ...
- 详解JavaScript闭包
要想完全明白JavaScript的闭包,要先明白js中的一些基础原理,然后我再给出一些例子来讲解闭包. 在执行JavaScript时会创建一个执行环境(excution context),执行环境定义 ...
- webstorm 编辑器破解 (麻麻再也不用担心过期了)
先去官网下载webstorm2016.1.3版本(目前只知道2016.1这个版本可以永久破解,不会过期) 再下载webstorm2016.1的破解补丁 将下载好的破解补丁解压,会有一个Jetbrain ...
- linux-网络数据包抓取-tcpdump
用法格式: tcpdump [-i 网卡] [选项] '表达式' 选项说明如下: -i:interface 监听的网卡. -nn:表示以ip和port的方式显示来源主机和目的主机,而不是用主机名和 ...
- Java多线程——深入重入锁ReentrantLock
简述 ReentrantLock 是一个可重入的互斥(/独占)锁,又称为“独占锁”. ReentrantLock通过自定义队列同步器(AQS-AbstractQueuedSychronized,是实现 ...
- PHP学习笔记之PDO
1. 何为PDO? PDO(PHP数据对象) 是一个轻量级的.具有兼容接口的PHP数据连接拓展,是一个PHP官方的PECL库,随PHP 5.1发布,需要PHP 5的面向对象支持,因而在更早的版本上无法 ...