zoukankan      html  css  js  c++  java
  • bzoj 2957: 楼房重建 线段树

    2957: 楼房重建

    Time Limit: 10 Sec  Memory Limit: 256 MB
    [Submit][Status][Discuss]

    Description

      小A的楼房外有一大片施工工地,工地上有N栋待建的楼房。每天,这片工地上的房子拆了又建、建了又拆。他经常无聊地看着窗外发呆,数自己能够看到多少栋房子。
      为了简化问题,我们考虑这些事件发生在一个二维平面上。小A在平面上(0,0)点的位置,第i栋楼房可以用一条连接(i,0)和(i,Hi)的线段表示,其中Hi为第i栋楼房的高度。如果这栋楼房上任何一个高度大于0的点与(0,0)的连线没有与之前的线段相交,那么这栋楼房就被认为是可见的。
      施工队的建造总共进行了M天。初始时,所有楼房都还没有开始建造,它们的高度均为0。在第i天,建筑队将会将横坐标为Xi的房屋的高度变为Yi(高度可以比原来大---修建,也可以比原来小---拆除,甚至可以保持不变---建筑队这天什么事也没做)。请你帮小A数数每天在建筑队完工之后,他能看到多少栋楼房?

    Input

      第一行两个正整数N,M
      接下来M行,每行两个正整数Xi,Yi

    Output


      M行,第i行一个整数表示第i天过后小A能看到的楼房有多少栋

    Sample Input


    3 4
    2 4
    3 6
    1 1000000000
    1 1

    Sample Output


    1
    1
    1
    2
    数据约定
      对于所有的数据1<=Xi<=N,1<=Yi<=10^9
    N,M<=100000

    HINT

     

    Source

    中国国家队清华集训 2012-2013 第一天

    看hzwer的

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=4e5+100,M=4e6+10,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    struct is
    {
        int l,r;
        double maxx;
        int ans;
    }tree[N];
    void build(int l,int r,int pos)
    {
        tree[pos].l=l;
        tree[pos].r=r;
        tree[pos].ans=0;
        tree[pos].maxx=0.0;
        if(l==r)return;
        int mid=(l+r)>>1;
        build(l,mid,pos<<1);
        build(mid+1,r,pos<<1|1);
    }
    int getans(double v,int pos)
    {
        if(tree[pos].l==tree[pos].r)
            return (tree[pos].maxx>v);
        if(tree[pos<<1].maxx<=v)
            return getans(v,pos<<1|1);
        return tree[pos].ans-tree[pos<<1].ans+getans(v,pos<<1);
    }
    void pushup(int pos)
    {
        tree[pos].maxx=max(tree[pos<<1].maxx,tree[pos<<1|1].maxx);
        tree[pos].ans=tree[pos<<1].ans+getans(tree[pos<<1].maxx,pos<<1|1);
    }
    void update(int p,double c,int pos)
    {
        if(tree[pos].l==tree[pos].r)
        {
            tree[pos].maxx=c;
            tree[pos].ans=1;
            return;
        }
        int mid=(tree[pos].l+tree[pos].r)>>1;
        if(p<=mid)
            update(p,c,pos<<1);
        else
            update(p,c,pos<<1|1);
        pushup(pos);
    }
    int main()
    {
        int n,m;
        while(~scanf("%d%d",&n,&m))
        {
            build(1,n,1);
            while(m--)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                update(x,(double)(y/x),1);
                printf("%d
    ",tree[1].ans);
            }
        }
        return 0;
    }
  • 相关阅读:
    localStorage、sessionStorage详解,以及storage事件使用
    企业和开发人员究竟该如何适应web标准?
    平面设计常用制作尺寸
    git命令
    TCP/IP、Http、Socket的区别
    canvas
    《千克》
    《小数的加法》
    fiddler设置代理
    《分数的基本性质》
  • 原文地址:https://www.cnblogs.com/jhz033/p/5950528.html
Copyright © 2011-2022 走看看