[POI2005]AUT-The Bus 树状数组维护最大前缀和
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100000+3;
int x[N], y[N], Y[N], A[N], nums[N];
int C[N];
int cmp(int i,int j){
if(x[i]==x[j])return y[i]<y[j];
return x[i]<x[j];
}
int lowbit(int t){return t&(-t);}
void update(int t,int delta)
{
while(t<N) C[t]=max(C[t],delta), t+=lowbit(t);
}
int query(int t){
int tmp=-1;
while(t>0)tmp=max(tmp,C[t]), t-=lowbit(t);
return tmp;
}
int main()
{
//freopen("in.txt","r",stdin);
int n,m,k,ans=0;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;++i)scanf("%d%d%d",&y[i],&x[i],&nums[i]), Y[i]=y[i];
for(int i=1;i<=k;++i)A[i]=i;
sort(A+1,A+1+k,cmp);
sort(Y+1,Y+1+k);
for(int i=1;i<=k;++i)
{
int cur=A[i];
y[cur]=lower_bound(Y+1,Y+1+k, y[cur])-Y;
int h=query(y[cur])+nums[cur];
ans=max(ans,h);
update(y[cur], h);
}
printf("%d",ans);
return 0;
}
[POI2005]AUT-The Bus 树状数组维护最大前缀和的更多相关文章
- [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)
树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...
- HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gc ...
- POJ 3321 Apple Tree(后根遍历将树转化成序列,用树状数组维护)
题意:一棵树,有很多分叉,每个分叉上最多有1个苹果. 给出n,接下来n-1行,每行u,v,表示分叉u,v之间有树枝相连.这里数据中u相当于树中的父节点,v相当于子节点. 给出两个操作: 1.C x ...
- 第十二届湖南省赛G - Parenthesis (树状数组维护)
Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...
- LOJ107. 维护全序集【树状数组维护全序集】
题目描述 这是一道模板题,其数据比「普通平衡树」更强. 如未特别说明,以下所有数据均为整数. 维护一个多重集 S ,初始为空,有以下几种操作: 把 x 加入 S 删除 S 中的一个 x,保证删除的 x ...
- 【BZOJ2124】等差子序列 树状数组维护hash值
[BZOJ2124]等差子序列 Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】
任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...
随机推荐
- Spring MVC学习总结(4)——SpringMVC权限管理
1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServlet. DispatcherServl ...
- ACdream 1735 输油管道
输油管道 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 262144/131072KB (Java/Others) Problem Des ...
- Tensorflow 0.8.0 安装配置方法
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51280087 折腾了一下,给工作站配置 ...
- 0802关于mysql数据库的锁机制
参考网址 http://www.cnblogs.com/yelbosh/p/5813865.html http://www.cnblogs.com/chenpingzhao/p/5065316.htm ...
- 洛谷——P1616 疯狂的采药
https://www.luogu.org/problem/show?pid=1616#sub 题目背景 此题为NOIP2005普及组第三题的疯狂版. 题目描述 LiYuxiang是个天资聪颖的孩子, ...
- 关于template 的23个问题
发现新大陆.曾经慢慢才知道的东西.原来有个集中营: 看看updated, 处理方式是这么的好 35.1 " id="link-to-faq-35_1" style=&qu ...
- MVVM设计模式基础知识--ICommand接口
命令是 Windows Presentation Foundation (WPF) 中的输入机制,它提供的输入处理比设备输入具有更高的语义级别. 命令有若干用途: 第一个用途是将语义以及调用命令的对象 ...
- Ural 1167 Bicolored Horses (DP)
题目地址:Ural 1167 感觉这题的思路类似于背包的做法. . 先预处理出来每一个马与之前全部的马的0的数量和1的数量,用数组a[0][i]和a[1][i]来表示. 然后再用数组dp[i][j]来 ...
- ural 1005 Stone Pile
这是道01背包题 ,尽管背包不会 ,可是还是看出来了,递推公式写啊写没写出来,后来一同学说是dfs.这我就開始了A了, 题意是给你n个重量是Wn的石头 让你放到两个包里面.看他们两个差值最小, ...
- 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)
使用vector容器,即避免不了进行查找,所以今天就罗列一些stl的find算法应用于vector中. find() Returns an iterator to the first element ...