P4198 楼房重建 [线段树] [最长上升子序列]

传送门 

题解原网

#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; 
}

猜你喜欢

转载自blog.csdn.net/sslz_fsy/article/details/84996232
今日推荐