HDU 1541
来源:互联网 发布:羊毛毡 淘宝网 编辑:程序博客网 时间:2024/06/05 12:46
树状数组的应用,只是利用的它向后更新,向前查询的性质。
#include <stdio.h>#include <string.h>#define LEN 150001int tree[LEN];int level[LEN];int lowbit(int x) { return x & (-x); }void update(int pos) { while(pos <= LEN) { tree[pos] ++; pos += lowbit(pos); }}int query(int pos) { int sum = 0; while(pos > 0) { sum += tree[pos]; pos -= lowbit(pos); } return sum;}int main() { int num; while(scanf("%d", &num) != EOF) { int x, y; int i, j; memset(level, 0, sizeof(level)); memset(tree, 0, sizeof(tree)); for(i = 1; i <= num; i++) { scanf("%d%d", &x, &y); level[query(++x)]++; update(x); } for(i = 0; i < num; i++) { printf("%d\n", level[i]); } } return 0;}
- hdu 1541
- HDU 1541
- hdu 1541
- hdu 1541
- hdu 1541 Stars
- hdu 1541 star
- hdu 1541 stars
- hdu 1541 Stars
- HDU 1541 树状数组
- HDU 1541 Stars
- hdu 1541 Starts
- hdu 1541 Stars
- HDU 1541 Stars
- hdu 1541 Stars
- HDU 1541 Stars
- HDU 1541 树状数组
- HDU - 1541 Stars
- hdu 1541 Stars
- 链表 基本操作
- JavaScript实现图片之间切换
- ubuntu11.10编译android4.0
- CUDA VS Wizard 2.9 更新
- html5(test1.提交表单)
- HDU 1541
- 浅析Eclipse建模框架(EMF)及其动态能力
- 解决img对大部分CSS样式不支持的问题
- UVA 673 Parentheses Balance
- Oracle Patchset v11203
- 权限系统的设置
- 某X公司的C/C++技能复核考试
- 查看sqlite数据库信息
- 学生管理系统 项目总结