博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【树状数组】POJ 2352 Stars
阅读量:6884 次
发布时间:2019-06-27

本文共 1061 字,大约阅读时间需要 3 分钟。

 
/** *  @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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int N = 15005;const int M = 32010;int level[N], c[M];int lowbit(int x) { return (x & (-x)) ;}// 向上更新void update(int x, int v) { while(x < M) { c[x] += v; x += lowbit(x); }}// 获取当前节点及下面的值的个数int getSum(int x) { int sum = 0; while(x > 0) { sum += c[x]; x -= lowbit(x); } return sum;}int main(){ int n, x, y; scanf ("%d", &n); memset(level, 0, sizeof(level)); memset(c, 0, sizeof(c)); for(int i = 1; i <= n; i ++) { scanf("%d%d", &x, &y); ++ level[getSum(x + 1)]; update(x+1, 1); } for(int i = 0; i < n; i ++) { cout << level[i] << endl; } return 0;}

附一篇经典翻译,学习 树状数组  

转载地址:http://dbnbl.baihongyu.com/

你可能感兴趣的文章
Linux 重定向符:> ,>>, <
查看>>
金融行业注册电子邮箱账号时最需要注意什么?
查看>>
Xhprof安装
查看>>
所谓的linux集群-其实可以so easy
查看>>
关于OOM-killer
查看>>
Wireshark网络抓包(一)——数据包、着色规则和提示
查看>>
GOP/ 码流 /码率 / 比特率 / 帧速率 / 分辨率
查看>>
学习一门编程语言的各种矛盾
查看>>
sqlmap简单使用笔记
查看>>
Eclipse ME 安装详解(Windows XP)
查看>>
IE8及以下不支持trim()的处理方法
查看>>
centos反编译APK包
查看>>
python 位操作符 左移和右移 运算
查看>>
预备作业①
查看>>
跨域 - jsonp轻松搞定跨域请求
查看>>
css布局 - 工作中常见的两栏布局案例及分析
查看>>
个人代码库のC#背景色渐变的功能
查看>>
基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境
查看>>
承接上面一遍的(后续步骤)
查看>>
杂笔感想
查看>>