poj 2352 Stars(树状数组)
2017-04-12 20:26
316 查看
树状数组不能处理0,树状数组不能处理0,树状数组不能处理0,重要的事情说3遍。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N=32010; int d ,c ; int lowbit(int x) { return x&(-x); } void add(int x) { while(x<N) { c[x]++; x+=lowbit(x); } } int sum(int x) { int ans=0; while(x>0) { ans+=c[x]; x-=lowbit(x); } return ans; } int main() { int n; int x,y; scanf("%d",&n); memset(d,0,sizeof(d)); for(int i=1;i<=n;i++) {scanf("%d%d",&x,&y);//x+1因为树状数组无法处理x=0 x++; d[sum(x)]++; add(x); } for(int i=0;i<n;i++) printf("%d\n",d[i]); return 0; }
相关文章推荐
- poj2352--Stars--线段树&树状数组
- POJ 2352 Stars (树状数组)
- POJ 2352 Stars(树状数组)
- 【原】 POJ 2352 Stars 树状数组 解题报告
- POJ 2352 Stars(简单树状数组)
- POJ_2352 Stars(树状数组)
- poj 2352 stars(树状数组)
- poj 2352 Stars (树状数组 + 1)
- [树状数组]POJ 2352 Stars
- POJ 2352 Stars(树状数组)
- POJ:2352 Stars(树状数组)
- poj 2352 Stars (树状数组)
- poj - 2352 - Stars(树状数组)
- (树状数组) poj 2352 Stars
- [poj 2352]Stars代码阅读记录[树状数组]
- POJ-2352 Stars【树状数组】
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- poj 2352 Stars (树状数组)
- POJ 2352 Stars(树状数组)