码迷,mamicode.com
首页 > 其他好文 > 详细

树状数组Hdu1541

时间:2014-06-10 00:09:07      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   color   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <iostream>
using namespace std;
int a[222222];
int ret[222222];
const int Max=33000;
int lowbit(int x)
{
    return x&(-x);
}
 
int ask(int k)
{
    int sum=0;
    while(k>0){
        sum+=a[k];
        k-=lowbit(k);
    }
    return sum;
}
 
void change(int x,int add)
{
    while(x<=Max){
        a[x]+=add;
        x+=lowbit(x);
    }
}
 
int main()
{
    int n,x,y;
    while(scanf("%d",&n)!=EOF){
        memset(a,0,sizeof(a));
        memset(ret,0,sizeof(ret));
        for(int i=0;i<n;i++){
            scanf("%d%d",&x,&y);
            change(x+1,1);
            int ans=ask(x+1)-1;
            ret[ans]++;
        }
        for(int i=0;i<n;i++)
            printf("%d\n",ret[i]);
    }
    return 0;
}

  

树状数组Hdu1541,布布扣,bubuko.com

树状数组Hdu1541

标签:c   class   blog   code   a   color   

原文地址:http://www.cnblogs.com/yigexigua/p/3773716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!