树状数组Hdu1541

?





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

时间: 2024-07-31 03:44:15

树状数组Hdu1541的相关文章

HDU1541 树状数组

Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8938    Accepted Submission(s): 3551 Problem Description Astronomers often examine star maps where stars are represented by points on a plan

HDU1541 Stars(树状数组)

Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7209    Accepted Submission(s): 2830 Problem Description Astronomers often examine star maps where stars are represented by points on a pla

HDU1541 Stars【树状数组】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意: 按顺序给你N颗星星的坐标,y是从小到大给出的.每个星星有一个等级,该等级为它左下角的星星 的个数.求每个等级的点有多少个. 思路: 因为y是从小到大给出的,那么可以直接忽略y,只记录x,求出(x,y)左边有多少个点就可以了. 用Ans[]数组表示每个等级的星星数.求(x,y)左边有多少个点用树状数组来做,每给一个点,就求出 x左边的点个数.作为Ans数组下标,累加个数,最后输出A

树状数组入门 hdu1541 Stars

树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次只能修改一个元素的值:经过简单修改可以在log(n)的复杂度下进行范围修改,但是这时只能查询其中一个元素的值(如果加入多个辅助数组则可以实现区间修改与区间查询). 树状数组和线段树很像,但能用树状数组解决的问题,基本上都能用线段树解决,而线段树能解决的树状数组不一定能解决.相比较而言,树状数组效率要

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

(POJ 3067) Japan (慢慢熟悉的树状数组)

Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29295   Accepted: 7902 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coas

【二维树状数组】See you~

https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/F [题意] 给定一个矩阵,每个格子的初始值为1.现在可以对矩阵有四种操作: A x y n1 :给格点(x,y)的值加n1 D x y n1: 给格点(x,y)的值减n1,如果现在格点的值不够n1,把格点置0 M x1 y1 x2 y2:(x1,y1)移动给(x2,y2)n1个 S x1 y1 x2 y2 查询子矩阵的和 [思路] 当然是二维树状数组 但是一定要注意:lowbi

Vijos P1066 弱弱的战壕【多解,线段树,暴力,树状数组】

弱弱的战壕 描述 永恒和mx正在玩一个即时战略游戏,名字嘛~~~~~~恕本人记性不好,忘了-_-b. mx在他的基地附近建立了n个战壕,每个战壕都是一个独立的作战单位,射程可以达到无限(“mx不赢定了?!?”永恒[email protected][email protected]). 但是,战壕有一个弱点,就是只能攻击它的左下方,说白了就是横纵坐标都不大于它的点(mx:“我的战壕为什么这么菜”ToT).这样,永恒就可以从别的地方进攻摧毁战壕,从而消灭mx的部队. 战壕都有一个保护范围,同它的攻击

CF 313 DIV2 B 树状数组

http://codeforces.com/contest/313/problem/B 题目大意 给一个区间,问你这个区间里面有几个连续相同的字符. 思路: 表示个人用树状数组来写的...了解了树状数组的本质就行了. 当然用sum[r]-sum[l]也是可以的