[BZOJ] 2957: 楼房重建

见7.3测试

#include<iostream>
#include<cstdio>

using namespace std;

inline int rd(){
  int ret=0,f=1;char c;
  while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
  while(isdigit(c))ret=ret*10+c-'0',c=getchar();
  return ret*f;
}

const int MAXN=100005;
int n,m;

#define mid ((l+r)>>1)
#define ls (cur<<1)
#define rs (cur<<1|1)
double mx[MAXN<<2],mn[MAXN<<2];
int len[MAXN<<2];

int query(int cur,int l,int r,double w){
  if(l==r) return mx[cur]>w;
  if(mx[ls]<=w) return query(rs,mid+1,r,w);
  return query(ls,l,mid,w)+len[cur]-len[ls];
}

void pushup(int cur,int l,int r){
    mx[cur]=max(mx[ls],mx[rs]);
  len[cur]=len[ls]+query(rs,mid+1,r,mx[ls]);
}

void update(int x,int cur,int l,int r,double w){
    if(l==r){mx[cur]=w;len[cur]=1;return;}
    if(x<=mid) update(x,ls,l,mid,w);
    if(mid <x) update(x,rs,mid+1,r,w);
    pushup(cur,l,r);
}

int main(){
    n=rd();m=rd();
    int x,y;
    for(int i=1;i<=m;i++){
        x=rd();y=rd();
        double d=1.0*y/x;
        update(x,1,1,n,d);
        printf("%d\n",len[1]);
    }
    return 0;
}

 

posted @ 2018-07-03 21:05  GhostCai  阅读(67)  评论(0编辑  收藏