zoukankan      html  css  js  c++  java
  • hdu1541Stars(树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=1541

    题被划在线段树里 刚开始想着是求区间k值 写着写着觉得错了 看着像求逆序数 写了个树状数组 怎么都过不了 无奈。。

    View Code
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 #define N 50000
     7 struct node
     8 {
     9     int x,y,p;
    10 }s[N<<1];
    11 int po[N<<1],re[N<<2],n,num[N<<1],w = N;
    12 bool cmpp(struct node a,struct node b)
    13 {
    14     return a.x<b.x;
    15 }
    16 void add(int i,int da)
    17  {
    18      while(i<=w)
    19      {
    20         re[i]+=da;
    21         i += i&(-i);
    22      }
    23  }
    24  int getsum(int i)
    25  {
    26      int s = 0;
    27      while(i)
    28      {
    29          s+=re[i];
    30          i-=i&(-i);
    31      }
    32      return s;
    33  }
    34 int main()
    35 {
    36     int i,j,k;
    37     while(~scanf("%d", &n))
    38     {
    39         memset(re,0,sizeof(re));
    40         memset(num,0,sizeof(num));
    41         for(i = 1; i <= n ; i++)
    42         {
    43             scanf("%d%d",&s[i].x,&s[i].y);
    44             s[i].x++;
    45             k = getsum(s[i].x);
    46             num[k]++;
    47             add(s[i].x,1);
    48         }
    49         for(i = 0 ; i < n ; i++)
    50         printf("%d\n",num[i]);
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    A 第一课 链表
    CSS基础_01:
    html基础(2)
    冒泡_选择算法
    高等数学以及Python 实现
    ubuntu18.04 镜像下载
    MatplotLib 第二部分
    一件很好笑的事情
    HIVE文件
    一个关于消息结构体的讨论
  • 原文地址:https://www.cnblogs.com/shangyu/p/2734381.html
Copyright © 2011-2022 走看看