P3431 [POI2005]AUT-The Bus(二维偏序、树状数组)
标签:void cond tar cin define name target tor www
https://www.luogu.org/problem/P3431
二维偏序经典题,树状数组维护下前缀最大值,dp思想。
1 #define bug(x) cout 2 #define IO std::ios::sync_with_stdio(0)
3 #define ull unsigned long long
4 #include 5 #define iter ::iterator
6 #define pa pair 7 #define pp pair 8 using namespace std;
9 #define ll long long
10 #define mk make_pair
11 #define pb push_back
12 #define se second
13 #define fi first
14 #define ls o15 #define rs o16 const int N=1e5+5;
17 int n,m,q;
18 int mx=1e9;
19 pp p[N];
20 int c[N];
21 int low(ll x){
22 return x&(-x);
23 }
24 void add(int x,int y){
25 while(xq){
26 c[x]=max(c[x],y);
27 x+=low(x);
28 }
29 }
30 int qu(int x){
31 int res=0;
32 while(x){
33 res=max(res,c[x]);
34 x-=low(x);
35 }
36 return res;
37 }
38 int a[N];
39 int main(){
40 IO;
41 cin>>n>>m>>q;
42 for(int i=1;i){
43 cin>>p[i].fi>>p[i].se.fi>>p[i].se.se;
44 a[i]=p[i].se.fi;
45 }
46 sort(a+1,a+1+q);
47 int na=unique(a+1,a+1+q)-a-1;
48 sort(p+1,p+1+q);
49 ll ans=p[1].se.se;
50 int x=lower_bound(a+1,a+1+na,p[1].se.fi)-a;
51 add(x,ans);
52 for(int i=2;i){
53 int x=lower_bound(a+1,a+1+na,p[i].se.fi)-a;
54 ll res=qu(x)+p[i].se.se;
55 ans=max(ans,res);
56 add(x,res);
57 }
58 printf("%lld\n",ans);
59 }
P3431 [POI2005]AUT-The Bus(二维偏序、树状数组)
标签:void cond tar cin define name target tor www
原文地址:https://www.cnblogs.com/ccsu-kid/p/11548118.html
评论