标签:code log algorithm data turn src def discus rip
1 #pragma GCC optimze("O3") 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<cstring> 6 #include<queue> 7 #include<algorithm> 8 #include<cmath> 9 #include<map> 10 #define N 100005 11 using namespace std; 12 int f[N],n,m,t,zz,jg[N]; 13 struct no 14 { 15 int x,y,data; 16 }node[N]; 17 map<int,int> ls; 18 bool px(no a,no b) 19 { 20 if(a.x==b.x)return a.y<b.y; 21 return a.x<b.x; 22 } 23 int a[N]; 24 int lowbit(int x) 25 { 26 return x&(-x); 27 } 28 void add(int x,int z) 29 { 30 for(int i=x;i<=m;i+=lowbit(i)) 31 a[i]=max(a[i],z); 32 } 33 int get(int x) 34 { 35 int ans=0; 36 for(int i=x;i>0;i-=lowbit(i)) 37 ans=max(ans,a[i]); 38 return ans; 39 } 40 int main() 41 { 42 scanf("%d%d%d",&n,&m,&t); 43 for(int i=1;i<=t;i++) 44 { 45 scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].data); 46 if(!ls[node[i].y]) 47 { 48 zz++; 49 ls[node[i].y]=1; 50 jg[zz]=node[i].y; 51 } 52 } 53 sort(node+1,node+t+1,px); 54 sort(jg+1,jg+zz+1); 55 for(int i=1;i<=zz;i++) 56 ls[jg[i]]=i; 57 m=zz; 58 for(int i=1;i<=t;i++) 59 node[i].y=ls[node[i].y]; 60 int ans=0; 61 for(int i=1;i<=t;i++) 62 { 63 f[i]=get(node[i].y)+node[i].data; 64 add(node[i].y,f[i]); 65 } 66 printf("%d\n",get(m)); 67 return 0; 68 }
Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
标签:code log algorithm data turn src def discus rip
原文地址:http://www.cnblogs.com/liutianrui/p/7588520.html