社区讨论

50分玄关,悬关

P4198楼房重建参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lu18yck2
此快照首次捕获于
2024/03/21 21:07
2 年前
此快照最后确认于
2024/03/22 08:42
2 年前
查看原帖
rt,code:
CPP
#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;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...