1 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #include <algorithm> 6 #include <map> 7 using namespace std; 8 const int Maxn=100100; 9 int n,m,k,c[Maxn],F[Maxn]; 10 map<int,int> M; 11 struct Info{int x,y,z;}P[Maxn]; 12 inline bool cmp(Info A,Info B) {return A.x<B.x || (A.x==B.x && A.y<B.y);} 13 inline int Max(int x,int y) {return x>y?x:y;} 14 inline int Lowbit(int x) {return x&(-x);} 15 inline int Query(int x){int Ret=0; for (int i=x;i;i-=Lowbit(i)) Ret=Max(Ret,c[i]); return Ret;} 16 inline void Update(int x,int y) {for (int i=x;i<=k;i+=Lowbit(i)) c[i]=Max(c[i],y);} 17 int main() 18 19 { 20 scanf("%d%d%d",&n,&m,&k); 21 for (int i=1;i<=k;i++) scanf("%d%d%d",&P[i].x,&P[i].y,&P[i].z),M[P[i].y]=1; 22 int Cnt=0; sort(P+1,P+k+1,cmp); 23 for (map<int,int>::iterator it=M.begin();it!=M.end();it++) it->second=++Cnt; 24 for (int i=1;i<=k;i++) P[i].y=M[P[i].y]; 25 for (int i=1;i<=k;i++) 26 { 27 F[i]=Query(P[i].y)+P[i].z; 28 Update(P[i].y,F[i]); 29 } 30 int Ans=0; 31 for (int i=1;i<=k;i++) Ans=Max(Ans,F[i]); 32 printf("%d\n",Ans); 33 return 0; 34 }
C++
时间: 2024-10-25 07:50:33