HDU6447(离散化扫描线+树状数组)

一眼看过去就x排序扫描一下,y是1e9的离散化一下,每层用树状数组维护一下,然后像dp倒着循环似的树状数组就用y倒着插就可行了。

类似题目练习:BZOJ4653BZOJ1218

 

  1 #pragma comment(linker, "/STACK:1024000000,1024000000")
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cstdlib>
  5 #include <cmath>
  6 #include <ctime>
  7 #include <cctype>
  8 #include <climits>
  9 #include <iostream>
 10 #include <iomanip>
 11 #include <algorithm>
 12 #include <string>
 13 #include <sstream>
 14 #include <stack>
 15 #include <queue>
 16 #include <set>
 17 #include <map>
 18 #include <vector>
 19 #include <list>
 20 #include <fstream>
 21 #include <bitset>
 22 #define init(a, b) memset(a, b, sizeof(a))
 23 #define rep(i, a, b) for (int i = a; i <= b; i++)
 24 #define irep(i, a, b) for (int i = a; i >= b; i--)
 25 using namespace std;
 26 
 27 typedef double db;
 28 typedef long long ll;
 29 typedef unsigned long long ull;
 30 typedef pair<int, int> P;
 31 const int inf = 0x3f3f3f3f;
 32 const ll INF = 1e18;
 33 
 34 template <typename T> void read(T &x) {
 35     x = 0;
 36     int s = 1, c = getchar();
 37     for (; !isdigit(c); c = getchar())
 38         if (c == '-')    s = -1;
 39     for (; isdigit(c); c = getchar())
 40         x = x * 10 + c - 48;
 41     x *= s;
 42 }
 43 
 44 template <typename T> void write(T x) {
 45     if (x < 0)    x = -x, putchar('-');
 46     if (x > 9)    write(x / 10);
 47     putchar(x % 10 + '0');
 48 }
 49 
 50 template <typename T> void writeln(T x) {
 51     write(x);
 52     puts("");
 53 }
 54 
 55 const int maxn = 1e5 + 5;
 56 int T, n;
 57 struct cord {
 58     int x, y, v;
 59 
 60     bool operator < (const cord& rhs) const {
 61         if (x != rhs.x) return x < rhs.x;
 62         return y > rhs.y;
 63     }
 64 }a[maxn];
 65 int yy[maxn], tot;
 66 struct BIT {
 67     int F[maxn];
 68 
 69     void Update(int pos, int val) {
 70         for (; pos <= tot; pos += pos&-pos)
 71             F[pos] = max(F[pos], val);
 72     }
 73 
 74     int Query(int pos) {
 75         int ret = 0;
 76         for (; pos; pos -= pos&-pos)
 77             ret = max(ret, F[pos]);
 78         return ret;
 79     }
 80 }bit;
 81 
 82 int main() {
 83     for (read(T); T; T--, tot = 0) {
 84         read(n);
 85         rep(i, 1, n) {
 86             read(a[i].x);
 87             read(a[i].y);
 88             read(a[i].v);
 89             yy[++tot] = a[i].y;
 90         }
 91         sort(yy + 1, yy + 1 + tot);
 92         tot = unique(yy + 1, yy + 1 + tot) - yy - 1;
 93         rep(i, 1, n) {
 94             a[i].y = lower_bound(yy + 1, yy + 1 + tot, a[i].y) - yy;
 95         }
 96 
 97         sort(a + 1, a + 1 + n);
 98         init(bit.F, 0);
 99         rep(i, 1, n) {
100             bit.Update(a[i].y, bit.Query(a[i].y - 1) + a[i].v);
101         }
102         writeln(bit.Query(tot));
103     }
104     return 0;
105 }

 

posted @ 2019-03-25 23:53  AlphaWA  阅读(359)  评论(0编辑  收藏  举报