码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ1537 [POI2005]Aut- The Bus

时间:2014-11-30 13:52:51      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

恩。。。一开始以为是二维树状数组随便搞。。。

后来看到数据范围额。。。

好吧,首先离散化x,按y排序,然后树状数组维护前缀和最大值即可。

(zky巨巨说是dp,那就算是dp好了,唔~)

离散化的时候偷懒用了map 233

 

bubuko.com,布布扣
 1 /**************************************************************
 2     Problem: 1537
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:780 ms
 7     Memory:5412 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12 #include <map>
13  
14 #define lowbit(x) x & -x
15 using namespace std;
16 typedef map <int, int> Map;
17 typedef Map::iterator ITER;
18 const int N = 100005;
19  
20 struct point {
21     int x, y, v;
22     inline bool operator < (const point &b) const {
23         return y == b.y ? x < b.x : y < b.y;
24     }
25 } a[N];
26  
27 Map w;
28 int n, BIT[N], tot, ans;
29  
30 inline int read() {
31     int x = 0;
32     char ch = getchar();
33     while (ch < 0 || 9 < ch)
34         ch = getchar();
35     while (0 <= ch && ch <= 9) {
36         x = x * 10 + ch - 0;
37         ch = getchar();
38     }
39     return x;
40 }
41  
42 inline void update(int x, int d) {
43     while (x <= n)
44         BIT[x] = max(BIT[x], d), x += lowbit(x);
45 }
46  
47 inline int query(int x) {
48     int res = 0;
49     while (x)
50         res = max(res, BIT[x]), x -= lowbit(x);
51     return res;
52 }
53  
54  
55 int main() {
56     int i, x;
57     ITER it;
58     read(), read(), n = read();
59     for (i = 1; i <= n; ++i) {
60         a[i].x = read(), a[i].y = read(), a[i].v = read();
61         w[a[i].x] = 1;
62     }
63     sort(a + 1, a + n + 1);
64     for (it = w.begin(); it != w.end(); ++it)
65         it -> second = ++tot;
66     for (i = 1; i <= n; ++i)
67         a[i].x = w[a[i].x];
68     for (i = 1; i <= n; ++i) {
69         x = query(a[i].x) + a[i].v;
70         update(a[i].x, x);
71         ans = max(ans, x);
72     }
73     printf("%d\n", ans);
74     return 0;
75 }
View Code

 

BZOJ1537 [POI2005]Aut- The Bus

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/rausen/p/4132859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!