#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. YOLOV3 训练WIDER_FACE

    1. dowload the img and labels : http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/index.html 2.

  2. synchronized 底层实现原理

    线程在获取锁的时候,其指针指向的是一个monitor对象(由C++实现)的起始地址.每个对象实例都会有一个 monitor.其中monitor可以与对象一起创建.销毁:亦或者当线程试图获取对象锁时自动 ...

  3. 【php设计模式】代理模式

    代理模式就是实现一个类代表另一个类的功能的一种结构性设计模式. 主要解决在直接访问对象时带来的问题,比如说:要访问的对象在远程的机器上.在面向对象系统中,有些对象由于某些原因(比如对象创建开销很大,或 ...

  4. asp.net mvc 导出Excel

    [HttpGet] public void ExportNissan(string CheckListNo) { JObject queryParam; if (CheckListNo == null ...

  5. split分离特殊字符

    Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ ) \b  \t  \n  \f  \r  \ ...

  6. 微信小程序开发(十一)获取手机的完整详细信息

    // succ.wxml <view style='position:absolute; top:30%; left:35%;font-size:36rpx'>{{name}}:签到成功. ...

  7. 一个线程相关的高CPU占用问题的定位

    最近在重构项目代码时,发现两个线程同时访问一个加锁的std::list队列时,会出现恶性竞争锁的现象. 具体现象是A线程总是拿不到锁,B线程抢占几次后,A才抢占到. 由于是重构项目,也无法通过回滚代码 ...

  8. 通过自动回复机器人学Mybatis---基础版

    第1章 案例简介 介绍要实现的案例情况,后面会通过这个案例来学习 Mybatis 第2章 实战第一部----黎明前的黑暗 在没有 Mybatis 的情况下,使用 Jsp + Servlet + Jdb ...

  9. sysbench库文件路径不对

    #sysbench --versionsysbench: error while loading shared libraries: libmysqlclient.so .20: cannot ope ...

  10. vue--directive自定义指令(不常用)

    除了核心功能默认内置的指令 (v-model 和 v-show),Vue 也允许注册自定义指令.注意,在 Vue2.0 中,代码复用和抽象的主要形式是组件.然而,有的情况下,你仍然需要对普通 DOM ...