GYM 101889F(树状数组)
bit扫描坐标套路题,注意有重复的点,莽WA了。
const int maxn = 1e5 + 5;
struct node {
ll B, F, D;
bool operator < (const node &rhs) const {
if (B != rhs.B) return B > rhs.B;
return F < rhs.F;
}
}a[maxn];
int n, tot;
ll c[maxn], ans;
struct BIT {
ll t[maxn];
void Modify(int x, ll val) {
for (; x; x -= x&-x)
t[x] = max(t[x], val);
}
ll Query(int x) {
ll ret = 0;
for (; x <= tot; x += x&-x)
ret = max(t[x], ret);
return ret;
}
}T;
int main() {
read(n);
rep(i, 1, n) {
read(a[i].B);
read(a[i].F);
read(a[i].D);
c[++tot] = a[i].F;
}
sort(c + 1, c + tot + 1);
tot = unique(c + 1, c + 1 + tot) - c - 1;
rep(i, 1, n) {
a[i].F = lower_bound(c + 1, c + 1 + tot, a[i].F) - c;
}
sort(a + 1, a + 1 + n);
ll tmp = 0;
rep(i, 1, n) {
if (a[i].B == a[i - 1].B && a[i].F == a[i - 1].F)
tmp += a[i].D;
else tmp = T.Query(a[i].F + 1) + a[i].D;
ans = max(ans, tmp);
T.Modify(a[i].F, tmp);
}
writeln(ans);
return 0;
}
GYM 101889F(树状数组)的更多相关文章
- Gym - 101908C 树状数组 逆序对
Grandpa Giuseppe won a professional pizza cutter, the kind of type reel and, to celebrate, baked a r ...
- Codeforces Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- Gym 101908C - Pizza Cutter - [树状数组]
题目链接:https://codeforces.com/gym/101908/problem/C 题意: 一块正方形披萨,有 $H$ 刀是横切的,$V$ 刀是竖切的,不存在大于等于三条直线交于一点.求 ...
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...
- Gym 100960G (set+树状数组)
Problem Youngling Tournament 题目大意 给一个序列a[i],每次操作可以更改一个数,每次询问 将序列排序后有多少个数a[i]>=sum[i-1]. n<=10^ ...
- Gym - 101755G Underpalindromity (树状数组)
Let us call underpalindromity of array b of length k the minimal number of times one need to increme ...
- Gym - 100269F Flight Boarding Optimization(dp+树状数组)
原题链接 题意: 现在有n个人,s个位置和你可以划分长k个区域你可以把s个位置划分成k个区域,这样每个人坐下你的代价是该区域内,在你之前比你小的人的数量问你怎么划分这s个位置(当然,每个区域必须是连续 ...
- 【容斥原理】【推导】【树状数组】Gym - 101485G - Guessing Camels
题意:给你三个1~n的排列a,b,c,问你在 (i,j)(1<=i<=n,1<=j<=n,i≠j),有多少个有序实数对(i,j)满足在三个排列中,i都在j的前面. 暴力求的话是 ...
- Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)
题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...
- gym 100589A queries on the Tree 树状数组 + 分块
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数 ...
随机推荐
- 深入浅出剖析C语言函数指针与回调函数(一)【转】
本文转载自:http://blog.csdn.net/morixinguan/article/details/65494239 关于静态库和动态库的使用和制作方法. http://blog.csdn. ...
- codeforces 569D D. Symmetric and Transitive(bell数+dp)
题目链接: D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabyte ...
- CNN中下一层Feature map大小计算
符号表示: $W$:表示当前层Feature map的大小. $K$:表示kernel的大小. $S$:表示Stride的大小. 具体来讲: 整体说来,和下一层Feature map大小最为密切的就是 ...
- poj3565Ants——KM算法
题目:http://poj.org/problem?id=3565 首先,我们神奇地发现,没有相交边的匹配可以转化为距离和最小的匹配,所以可以使用KM算法求带权匹配: 要求的是距离和最小,所以把边权转 ...
- ubuntu系统,关于源(source)的配置
1. 现象:(出现的错误) 执行 sudo apt-get update, 报错:apt-get 404 Not Found Package Repository Errors 执行 sudo apt ...
- Ubuntu+win7 双系统修改开机启动项顺序
Ubuntu和windows双系统安装完后默认Ubuntu系统是第一启动项,等待时间是10秒 如果你想改成windows为第一启动项 先进去Ubuntu系统 打开终端 (Ctrl+Alt+T) 修改启 ...
- Android四种启动模式
四种启动模式 standard(默认) singleTop singleTast singleInstance standard(默认) 系统默认的启动模式. Android是使用返回栈来管理活动的, ...
- __attribute__((noreturn))的用法
外文地址:http://www.unixwiz.net/techtips/gnu-c-attributes.html __attribute__ noreturn 表示没有返回值 This at ...
- Broken robot
题意: 要在$nm$的矩阵中从 $(i,j)$ 处移动到第 $n$ 行,每次移动可在不动.左移一格.右移一格.下移一格 4 种选择中等概率随机选一种,但移动不能超出矩阵.求移动次数的期望,最少保留4位 ...
- c++中IO输入输出流总结<二>
1 文件的打开和关闭 1.1 定义流对象 ifsteam iflie;//文件输入流对象 ifsteam iflie;//文件输出流对象 fsteam iflie;//文件输入输出流对象 1.2 打开 ...