三个RE,谁帮忙调一下
查看原帖
三个RE,谁帮忙调一下
858145
hdmgydkn楼主2024/3/31 10:49
#include <iostream>
#include <algorithm>
using namespace std;
#define N 1000005
size_t n,m,k,tot;
long long Ans;
struct node{
	long long x,y,z;
	bool friend operator<(const node& A,const node& B){
		if(A.x==B.x) return A.y<B.y;
		else return A.x<B.x;
	}
}q[N];
long long a[N],c[N];
size_t lowbit(long long x){return x&(-x);}
long long sum(size_t x){
	long long ans=0;
	while(x){
		ans=max(ans,c[x]);
		x-=lowbit(x);
	}
	return ans;
}
void add(size_t x,long long y){
	while(x<=tot){
		c[x]=max(c[x],y);
		x+=lowbit(x);
	}
}
int main(){
	cin>>n>>m>>k;
	for(size_t i=1;i<=k;i++){
		cin>>q[i].x>>q[i].y>>q[i].z;
		a[i]=q[i].y;
	}
	sort(a+1,a+n+1);
	tot=unique(a+1,a+n+1)-a-1;
	for(size_t i=1;i<=k;i++)
		q[i].y=lower_bound(a+1,a+tot+1,q[i].y)-a;
	sort(q+1,q+k+1);
	for(size_t i=1;i<=k;i++){
		long long x=sum(q[i].y)+q[i].z;
		Ans=max(Ans,x);
		add(q[i].y,x);
	}
	cout<<Ans<<endl;
	return 0;
}

三个RE,大佬帮忙看看。

2024/3/31 10:49
加载中...