zoukankan      html  css  js  c++  java
  • POJ2352 Stars 树状数组

    emm,ssy说可以直接CDQ分治...%%%但是注意到y是有序的,所以可以直接求一下前缀和就行了.

    题干:

        Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars.
    
        For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
    
        You are to write a program that will count the amounts of the stars of each level on a given map. 
    Input
        The first line of the input file contains a number of stars N (1<=N<=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0<=X,Y<=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.
    Output
        The output should contain N lines, one number per line. The first line contains amount of stars of the level 0, the second does amount of stars of the level 1 and so on, the last line contains amount of stars of the level N-1. 

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<ctime>
    #include<queue>
    #include<algorithm>
    #include<map>
    #include<cstring>
    using namespace std;
    #define duke(i,a,n) for(register int i = a;i <= n;i++)
    #define lv(i,a,n) for(register int i = a;i >= n;i--)
    #define clean(a) memset(a,0,sizeof(a))
    const int INF = 1 << 30;
    typedef long long ll;
    typedef double db;
    template <class T>
    void read(T &x)
    {
        char c;
        bool op = 0;
        while(c = getchar(), c < '0' || c > '9')
            if(c == '-') op = 1;
        x = c - '0';
        while(c = getchar(), c >= '0' && c <= '9')
            x = x * 10 + c - '0';
        if(op) x = -x;
    }
    template <class T>
    void write(T x)
    {
        if(x < 0) putchar('-'), x = -x;
        if(x >= 10) write(x / 10);
        putchar('0' + x % 10);
    }
    const int maxn = 32005;
    int tree[1000005];
    int ans[100005];
    int n;
    int lowbit(int x)
    {
        return x & -x;
    }
    void change(int x)
    {
        while(x <= maxn)
        {
            tree[x]++;
            x += lowbit(x);
        }
    }
    int query(int x)
    {
        int tot = 0;
        while(x > 0)
        {
            tot += tree[x];
            x -= lowbit(x);
        }
        return tot;
    }
    int main()
    {
        read(n);
        duke(i,1,n)
        {
            int x,y;
            read(x);read(y);
            ans[query(x + 1)]++;
            /*duke(j,1,n)
            {
                printf("%d ",query(j));
            }
            puts("");*/
            change(x + 1);
        }
        duke(i,0,n - 1)
        {
            printf("%d
    ",ans[i]);
        }
        return 0;
    }
  • 相关阅读:
    8.ffmpeg-基础常用知识
    7.SwrContext音频重采样使用
    6.AVCodecContext和AVCodec
    5.AVStream和AVCodecParameters
    Discuz论坛禁止匿名发贴,却出现匿名发帖或回复?找不到发帖用户,DZ如何禁止匿名发帖修改教程
    在独立服务器上通过Ubuntu 18.04+apache2+php5.6+mysql5.7+discuz!x3.4搭建的论坛实现伪静态的正确方法
    [源码] 2200套微信小程序源码
    discuz论坛更换目录后出现头像无法显示/ucenter无法进入
    discuz 您的服务器不支持 CURL,这将会导致应用无法安装。请联系您的服务商或者网站技术人员
    Discuz在服务器配置安装时出现xml_parser_create()不支持
  • 原文地址:https://www.cnblogs.com/DukeLv/p/9958273.html
Copyright © 2011-2022 走看看