树状数组维护前缀最大值+扫描线DP
#include"cstdio"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;
const int MAXN=1e5+5;
int n,m,c,maxn;
long long Tib[MAXN];
struct rpg{
int x,y,v;
int rey;
}a[MAXN];
bool cmp1(rpg a,rpg b){return a.y<b.y;}
bool cmp2(rpg a,rpg b){return a.x==b.x?a.y<b.y:a.x<b.x;}
long long cask(int x)
{
long long ans=0;
for(int i=x;i;i&=i-1) ans=max(ans,Tib[i]);
return ans;
}
void ins(int x,long long v)
{
for(int i=x;i<=maxn;i+=i&-i) Tib[i]=max(Tib[i],v);
return;
}
int main()
{
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=c;++i) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].v);
sort(a+1,a+c+1,cmp1);a[1].rey=1;
for(int i=2;i<=c;++i) a[i].rey=a[i].y==a[i-1].y?a[i-1].rey:a[i-1].rey+1;
maxn=a[c].rey;
sort(a+1,a+c+1,cmp2);
for(int i=1;i<=c;++i){
long long tmp=cask(a[i].rey)+a[i].v;
ins(a[i].rey,tmp);
}printf("%lld
",cask(maxn));
return 0;
}