50分玄关,悬关
查看原帖
50分玄关,悬关
705725
P_VICVIC_R楼主2024/3/21 21:05

rt,code:

#include<bits/stdc++.h>
#define int long long 
using namespace std;
static const int N=1000000;
struct Node{
	int l,r;
	double Slope;
	int Sum;
}T[N*4];
int n,m;
inline void Build(int rt,int l,int r){
	T[rt].l=l;
	T[rt].r=r;
	T[rt].Sum=0;
	T[rt].Slope=0.0;
	if(l==r){
		return ;
	}
	int mid=(l+r)>>1;
	Build(rt<<1,l,mid);
	Build(rt<<1|1,mid+1,r);
}
inline int Run(int rt,double Slope){
	int l=T[rt].l,
		r=T[rt].r;
	if(T[rt].Slope<=Slope)
		return 0;
	if(l==r)
		return T[rt].Slope>Slope;
	if(T[rt<<1].Slope<=Slope){
		return Run(rt<<1|1,Slope);
	}
	else{
		return Run(rt<<1,Slope)+T[rt].Sum-T[rt<<1].Sum;
	}
}
inline void PushUp(int rt){
	T[rt].Slope=max(T[rt<<1].Slope,T[rt<<1|1].Slope);
	T[rt].Sum=T[rt<<1].Sum+Run(rt<<1|1,T[rt<<1].Slope);
}
inline void Modify(int rt,int Kth,double Slope){
	if(T[rt].r<Kth||T[rt].l>Kth)
		return ;
	if(T[rt].l==Kth&&T[rt].r==Kth){
		T[rt].Slope=Slope;
		T[rt].Sum=1;
		return ;
	}
	Modify(rt<<1,Kth,Slope);
	Modify(rt<<1|1,Kth,Slope);
	PushUp(rt);
}
signed main(){
	std::cin.tie(nullptr) -> sync_with_stdio(false);
	std::cout.tie(nullptr)-> sync_with_stdio(false);
	cin>>n>>m;
	Build(1,1,n);
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		Modify(1,x,double(y/x));
		cout<<T[1].Sum<<'\n';
	}
	return 0;
}

2024/3/21 21:05
加载中...