bzoj1537
来源:互联网 发布:vscode js代码高亮 编辑:程序博客网 时间:2024/06/05 15:35
离散化 + 树状数组优化
学到了
#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)#define lb(x) (x&-x)inline int read(void){ int x = 0, c, f = 1; do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9'); do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9'); return x * f;}const int N = 101000, INF = 0x3f3f3f3f;struct note{ int y, d; friend bool operator < (const note &i, const note &j) { return i.y != j.y ? i.y < j.y : i.d < j.d; }}Y[N];struct node{ int x, y, z; friend bool operator < (const node &i,const node &j) { return i.x != j.x ? i.x < j.x : i.y < j.y; }}p[N];int cnt[N], n, A, B, Index, f[N];inline int Query(int x) { int re = -INF; for ( ; x; x ^= lb(x)) re = max(re, cnt[x]); return re;}inline void Updata(int pos,int x) { for (; pos <= Index; pos += lb(pos)) cnt[pos] = max(cnt[pos], x);}inline void init(void) { sort(Y + 1, Y + n + 1); for (int i = 1; i <= n; i++) { Index += Y[i].y != Y[i-1].y; p[Y[i].d].y = Index; } sort(p + 1, p + n + 1);}int main() { A = read(), B = read(), n = read(); for (int i = 1; i <= n; i++) { p[i].x = read(), Y[i].y = read(); Y[i].d = i, p[i].z = read(); } init(); int ans = 0; for (int i = 1; i <= n; i++) { f[i] = p[i].z + Query(p[i].y); Updata(p[i].y, f[i]); ans = max(ans, f[i]); } cout << ans << endl;}
阅读全文
0 0
- bzoj1537
- BZOJ1537/POI2005 The Bus
- BZOJ1537: [POI2005]Aut- The Bus
- BZOJ1537: [POI2005]Aut-The Bus
- bzoj1537 [POI2005]Aut- The Bus 树状数组+DP。
- 【bzoj1537】 POI2005 Aut- The Bus 离散化+树状数组优化DP
- 去掉标题和沉寂模式
- Python操作数据库
- codeforces——443A——Anton and Letters
- Java虚拟机之垃圾收集算法
- 喜欢的书籍列表
- bzoj1537
- Struts2_动态方法调用和使用通配符定义action
- UESTC 1595 老司机的毒奶 贪心+二叉树+优先队列
- Android-Android 的消息机制
- java反射浅析
- Linux下安装Zookeeper
- docker 常用命令
- tigase使用message-archiving组件进行消息存储,版本7.2.0-SNAPSHOT
- egg-multipart 中代码的分析(header)