标签:标准 update unique 个数 += script .com 信息 tor
#include <cstdio> #include <cstring> #include <algorithm> char buf[10000000], *ptr = buf - 1; inline int readint(){ int n = 0; while(*++ptr < ‘0‘ || *ptr > ‘9‘); while(*ptr <= ‘9‘ && *ptr >= ‘0‘) n = (n << 1) + (n << 3) + (*ptr++ & 15); return n; } const int maxn = 100000 + 10; inline void max(int &a, const int &b){ if(a < b) a = b; } int n, c[maxn] = {0}; int num[maxn], cnt; inline int Query(int pos){ int s = 0; for(int i = pos; i; i -= i & -i) max(s, c[i]); return s; } inline void Update(int pos, int val){ for(int i = pos; i <= cnt; i += i & -i) max(c[i], val); } struct Node{ int x, y, p; bool operator < (const Node &a) const{ return x == a.x ? y < a.y : x < a.x; } }no[maxn]; int main(){ buf[fread(buf, sizeof(char), sizeof(buf), stdin)] = 0; readint(); readint(); n = readint(); for(int i = 1; i <= n; i++){ no[i].x = readint(); num[i] = no[i].y = readint(); no[i].p = readint(); } std::sort(num + 1, num + n + 1); cnt = std::unique(num + 1, num + n + 1) - (num + 1); for(int i = 1; i <= n; i++) no[i].y = std::lower_bound(num + 1, num + cnt + 1, no[i].y) - num; std::sort(no + 1, no + n + 1); for(int t, i = 1; i <= n; i++){ t = Query(no[i].y); Update(no[i].y, no[i].p + t); } printf("%d\n", Query(cnt)); return 0; }
[BZOJ1537][POI2005]Aut- The Bus
标签:标准 update unique 个数 += script .com 信息 tor
原文地址:http://www.cnblogs.com/ruoruoruo/p/7635497.html