zoukankan      html  css  js  c++  java
  • CDOJ 842 天下归晋 树状数组

    天下归晋

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://acm.uestc.edu.cn/#/problem/show/842

    Description

    晋朝统一天下已有十年,曹魏、孙吴、蜀汉这些曾与天下相争的王朝,都成为了过眼云烟,仅留于故事之中。

    “爷爷,讲嘛讲嘛,再讲一次赤壁之战的故事嘛!”

    “你个死小子,都讲多少遍了,还听!”

    “就是想听打仗嘛!”

    “你小子啊...行,我就再讲一次。当时曹公率领八十万大军欲渡长江,那船队规模才叫一壮观啊,长江都铺成陆地啰。当时是这样部署的....”

    曹操的船队自西向东铺于长江之上,为了方便指挥,每艘船都被赋予了相应的等级。这个等级由该船西南方船只的数量决定,即不比该船靠东并且不比该船靠北的船的数目。那是一只多么庞大的船队啊,只惜周郎一把火,樯橹灰飞烟灭......

    “太刺激了,打仗好好玩啊!爷爷你怎么那么清楚当时的事儿,你的腿就是赤壁时断的吗?”

    通天的火光,被激流卷去的兄弟,无数的惨叫,折断后砸向自己左腿的船柱...

    看了眼激动的孙子,老者咂咂嘴,淡淡说道:“爬山采药时摔的”。

    Input

    第一行,一个整数n表示曹军船只的数量。

    接下来n行,每行一个对整数xi,yi。表示第i艘船的坐标。

    数据保证不会有两艘船在同一位置。

    1≤n≤100000,0≤xi,yi≤320001n100000,0xi,yi32000
    1000000000.

    Output

    n行,每行1个整数,分别表示从0级到n−1级的船的数量。

    行末不要有空格。

    Sample Input

    5
    1 1
    5 1
    7 1
    3 3
    5 5

    Sample Output

    1
    2
    1
    1
    0

    HINT


    题意

    题解:

     呀,这是一道逆序数的题,首先我们对于所有的坐标进行排序,然后依次扔进去,我们就可以利用树状数组进行查询了!

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 100001
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    int buf[10];
    inline void write(int i) {
      int p = 0;if(i == 0) p++;
      else while(i) {buf[p++] = i % 10;i /= 10;}
      for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
      printf("
    ");
    }
    */
    //***********************y***************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int lowbit(int x)
    {
        return x&-x;
    }
    
    struct node
    {
        int x,y;
    };
    
    int n,N;
    int d[maxn],ans[maxn];
    bool cmp(node a,node b)
    {
        if(a.x==b.x)
            return a.y<b.y;
        return a.x<b.x;
    }
    node a[maxn];
    void updata(int x,int y)
    {
        while(x<=N)
        {
            d[x]+=y;
            x+=lowbit(x);
        }
    }
    
    int sum(int x)
    {
        int s=0;
        while(x>0)
        {
            s+=d[x];
            x-=lowbit(x);
        }
        return s;
    }
    
    int main()
    {   
        n=read(),N=0;
        for(int i=0;i<n;i++)
        {
            a[i].x=read(),a[i].y=read();
            a[i].y++;
            N=max(N,a[i].y);
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++)
        {
            ans[sum(a[i].y)]++;
            updata(a[i].y,1);
        }
        for(int i=0;i<n;i++)
            printf("%d
    ",ans[i]);
    }
  • 相关阅读:
    关于datax的SqlServerReader 插件文档读取设置
    SQLyog13.1.1连接MySQL 8.0.19时出现的2058错误,加密方式因版本支持问题解决方法。
    mysql客户端版本太低的问题,应该是先改变加密方式再修改密码.client does not support authentication protocol requested by server consider upgrading mysql client
    IntelliJ IDEA的JavaWeb开发环境搭建
    异构数据源同步工具DataX Web用户手册(一、安装)
    datax安装
    Sql Server 中 根据具体的值 查找该值所在的表和字段
    1202. 交换字符串中的元素
    路径总和
    买卖股票的最佳时机(II)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4433289.html
Copyright © 2011-2022 走看看