#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
#define A first
#define B second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define eps 1e-9
#define PIE acos(-1)
#define cl(a,b) memset(a,b,sizeof(a))
#define fastio ios::sync_with_stdio(false);cin.tie(0);
#define lson l , mid , ls
#define rson mid + 1 , r , rs
#define ls (rt<<1)
#define rs (ls|1)
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define sqr(a) a*a
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int, int>
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"
using namespace std;
#define pll pair<ll,ll>
const int maxn=1e5+;
ll n,d[maxn<<];
ll tot;
vector<int>v;
//**********************************
struct Node{
ll x,y,v;
bool operator<(const Node& rhs){
if(x!=rhs.x)return x<rhs.x;
return y>rhs.y;
}
}node[maxn];
void update(ll x,ll val)
{
while(x<=sz(v)){
d[x]=max(d[x],val);
x+=lowbit(x);
}
}
ll query(int x)
{
ll ans=;
while(x){
ans=max(ans,d[x]);
x-=lowbit(x);
}
return ans;
}
inline int getid(int x){return lower_bound(all(v),x)-v.begin()+;}
//**********************************
map<pll,ll>Mp;
//**********************************
int main()
{
fastio;
cin>>n;
map<pll,ll>::iterator it;
rep(i,,n){
cin>>node[i].x>>node[i].y>>node[i].v,v.pb(node[i].y);
pii PII=mp(node[i].x,node[i].y);
it=Mp.find(PII);
if(it!=Mp.end())node[i].v+=Mp[PII],Mp.erase(PII);
Mp.insert(mp(PII,node[i].v));
}
sort(all(v));v.erase(unique(all(v)),v.end());
rep(i,,n)node[i].y=getid(node[i].y);
ll tot=;
sort(node,node+n);
ll ans=;
rep(i,,n){
ll tmp;
tmp=query(node[i].y-)+node[i].v;
ans=max(ans,tmp);
update(node[i].y,tmp);
}
cout<<ans<<endl;
return ;
}

树状数组优化dp,一维排序,一维离散化的更多相关文章

  1. HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

    题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...

  2. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  3. LUOGU P2344 奶牛抗议 (树状数组优化dp)

    传送门 解题思路 树状数组优化dp,f[i]表示前i个奶牛的分组的个数,那么很容易得出$f[i]=\sum\limits_{1\leq j\leq i}f[j-1]*(sum[i]\ge sum[j- ...

  4. 【题解】Music Festival(树状数组优化dp)

    [题解]Music Festival(树状数组优化dp) Gym - 101908F 题意:有\(n\)种节目,每种节目有起始时间和结束时间和权值.同一时刻只能看一个节目(边界不算),在所有种类都看过 ...

  5. 【题解】ARC101F Robots and Exits(DP转格路+树状数组优化DP)

    [题解]ARC101F Robots and Exits(DP转格路+树状数组优化DP) 先删去所有只能进入一个洞的机器人,这对答案没有贡献 考虑一个机器人只能进入两个洞,且真正的限制条件是操作的前缀 ...

  6. Codeforces 909C Python Indentation:树状数组优化dp

    题目链接:http://codeforces.com/contest/909/problem/C 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现. 现在有一种简化版的Pytho ...

  7. BZOJ3594: [Scoi2014]方伯伯的玉米田【二维树状数组优化DP】

    Description 方伯伯在自己的农田边散步,他突然发现田里的一排玉米非常的不美. 这排玉米一共有N株,它们的高度参差不齐. 方伯伯认为单调不下降序列很美,所以他决定先把一些玉米拔高,再把破坏美感 ...

  8. Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)

    题意: 线段树做法 分析: 因为每次都是在当前位置的前缀区间查询最大值,所以可以直接用树状数组优化.比线段树快了12ms~ 代码: #include<cstdio> #include< ...

  9. BZOJ 3594: [Scoi2014]方伯伯的玉米田 (二维树状数组优化DP)

    分析 首先每次增加的区间一定是[i,n][i,n][i,n]的形式.因为如果选择[i,j](j<n)[i,j](j<n)[i,j](j<n)肯定不如把后面的全部一起加111更优. 那 ...

  10. 4.9 省选模拟赛 划分序列 二分 结论 树状数组优化dp

    显然发现可以二分. 对于n<=100暴力dp f[i][j]表示前i个数分成j段对于当前的答案是否可行. 可以发现这个dp是可以被优化的 sum[i]-sum[j]<=mid sum[i] ...

随机推荐

  1. queryURLParams

    let url = 'http://www.douqu.com/index.html?name1=val1&name2=val2'; //1.提取问号后的字符 let asktext = ur ...

  2. el表达式获取url中携带的参数

    使用JSTL时,URL会被隐含的对象param包裹起来,使用param.变量名,直接获取值 <body>hello:${param.name}</body> 在使用jquery ...

  3. Django + mysql 在创建数据库出错

    错误:django.db.utils.OperationalError: (1366, "Incorrect string value: '\\xE6\\x96\\x87\\xE7\\xAB ...

  4. Spring源码解析 - springMVC核心代码

    一.首先来讲解下springMVC的底层工作流程 1.首先我们重点放在前端控制器(DispatcherServlet) 其类图: 因为从流程图看,用户的请求最先到达就是DispatcherServle ...

  5. UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

    # -*- coding:utf-8 -*- china=u'我爱你,中国' #china=china.encode('utf8') file_txt = open("zhongguo.tx ...

  6. 在springmvc框架中,通过ajax请求,响应至前端的中文显示是?

    今天遇到的一个问题,我通过ajax请求去访问控制器,然后通过控制器给我响应了一段json数据,但是里面的中文 在浏览上显示是??,我在web.xml 文件中是设置了编码过滤器的,但是估计这个编码过滤器 ...

  7. PAT Advanced 1020 Tree Traversals (25 分)

    1020 Tree Traversals (25 分)   Suppose that all the keys in a binary tree are distinct positive integ ...

  8. bug是前端还是后端

    分析bug是前端还是后端的   如何分析一个bug是前端还是后端的? 平常提bug的时候,前端开发和后端开发总是扯皮,不承认是对方的bug这种情况很容易判断,先抓包看请求报文,对着接口文档,看请求报文 ...

  9. centos 最小化安装pycharm

    首先找到安装地址 https://www.jetbrains.com/pycharm/download/#section=linux 选择linux. 打开浏览器的network监视,我用的chrom ...

  10. 挺棒的七个Python图形应用GUI开发框架

    作为Pyhon开发者,你迟早都会碰到图形用户界面(GUI)应用开发任务,目前市场上有大量Python GUI开发框架可供选择,Python wiki GUI programming给出了超过30个跨平 ...