P4198 樓房重建 [線段樹] [最長上升子序列]
阿新 • • 發佈:2018-12-15
#include<bits/stdc++.h> #define N 400050 using namespace std; int n,m,val[N]; double Max[N]; int Count(int x,int l,int r,double lim){ if(l>=r) return Max[x] > lim; int mid = (l+r) >> 1; if(Max[x<<1] <= lim) return Count(x<<1|1,mid+1,r,lim); else return val[x] - val[x<<1] + Count(x<<1,l,mid,lim); } void Update(int x,int l,int r,int pos,double k){ if(l==r){Max[x] = k; val[x] = 1; return;} int mid = (l+r) >> 1; if(pos<=mid) Update(x<<1,l,mid,pos,k); else Update(x<<1|1,mid+1,r,pos,k); Max[x] = max(Max[x<<1],Max[x<<1|1]); val[x] = val[x<<1] + Count(x<<1|1,mid+1,r,Max[x<<1]); } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); double k = y*1.0/x*1.0; Update(1,1,n,x,k); printf("%d\n",val[1]); } return 0; }