HDU6447(离散化扫描线+树状数组)
一眼看过去就x排序扫描一下,y是1e9的离散化一下,每层用树状数组维护一下,然后像dp倒着循环似的树状数组就用y倒着插就可行了。
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- #include <ctime>
- #include <cctype>
- #include <climits>
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <string>
- #include <sstream>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <vector>
- #include <list>
- #include <fstream>
- #include <bitset>
- #define init(a, b) memset(a, b, sizeof(a))
- #define rep(i, a, b) for (int i = a; i <= b; i++)
- #define irep(i, a, b) for (int i = a; i >= b; i--)
- using namespace std;
- typedef double db;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair<int, int> P;
- const int inf = 0x3f3f3f3f;
- const ll INF = 1e18;
- template <typename T> void read(T &x) {
- x = ;
- int s = , c = getchar();
- for (; !isdigit(c); c = getchar())
- if (c == '-') s = -;
- for (; isdigit(c); c = getchar())
- x = x * + c - ;
- x *= s;
- }
- template <typename T> void write(T x) {
- if (x < ) x = -x, putchar('-');
- if (x > ) write(x / );
- putchar(x % + '');
- }
- template <typename T> void writeln(T x) {
- write(x);
- puts("");
- }
- const int maxn = 1e5 + ;
- int T, n;
- struct cord {
- int x, y, v;
- bool operator < (const cord& rhs) const {
- if (x != rhs.x) return x < rhs.x;
- return y > rhs.y;
- }
- }a[maxn];
- int yy[maxn], tot;
- struct BIT {
- int F[maxn];
- void Update(int pos, int val) {
- for (; pos <= tot; pos += pos&-pos)
- F[pos] = max(F[pos], val);
- }
- int Query(int pos) {
- int ret = ;
- for (; pos; pos -= pos&-pos)
- ret = max(ret, F[pos]);
- return ret;
- }
- }bit;
- int main() {
- for (read(T); T; T--, tot = ) {
- read(n);
- rep(i, , n) {
- read(a[i].x);
- read(a[i].y);
- read(a[i].v);
- yy[++tot] = a[i].y;
- }
- sort(yy + , yy + + tot);
- tot = unique(yy + , yy + + tot) - yy - ;
- rep(i, , n) {
- a[i].y = lower_bound(yy + , yy + + tot, a[i].y) - yy;
- }
- sort(a + , a + + n);
- init(bit.F, );
- rep(i, , n) {
- bit.Update(a[i].y, bit.Query(a[i].y - ) + a[i].v);
- }
- writeln(bit.Query(tot));
- }
- return ;
- }
HDU6447(离散化扫描线+树状数组)的更多相关文章
- HDU 5862 Counting Intersections (离散化+扫描线+树状数组)
题意:给你若干个平行于坐标轴的,长度大于0的线段,且任意两个线段没有公共点,不会重合覆盖.问有多少个交点. 析:题意很明确,可是并不好做,可以先把平行与x轴和y轴的分开,然后把平行y轴的按y坐标从小到 ...
- 【BZOJ1818】[Cqoi2010]内部白点 扫描线+树状数组
[BZOJ1818][Cqoi2010]内部白点 Description 无限大正方形网格里有n个黑色的顶点,所有其他顶点都是白色的(网格的顶点即坐标为整数的点,又称整点).每秒钟,所有内部白点同时变 ...
- HDU 5862 Counting Intersections 扫描线+树状数组
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/ ...
- [BZOJ4822][CQOI2017]老C的任务(扫描线+树状数组)
4822: [Cqoi2017]老C的任务 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 379 Solved: 203[Submit][Statu ...
- FZU 2225 小茗的魔法阵 扫描线+树状数组
这个题和一个CF上的找"Z"的题差不多,都是扫描线+树状数组 从右上角的主对角线开始扫描,一直扫到左下角,每次更新,右延伸等于该扫描线的点,注意在其所在的树状数组更新就好了 时间复 ...
- 【loj6041】「雅礼集训 2017 Day7」事情的相似度 后缀自动机+STL-set+启发式合并+离线+扫描线+树状数组
题目描述 给你一个长度为 $n$ 的01串,$m$ 次询问,每次询问给出 $l$ .$r$ ,求从 $[l,r]$ 中选出两个不同的前缀的最长公共后缀长度的最大值. $n,m\le 10^5$ 题解 ...
- 【bzoj4540】[Hnoi2016]序列 单调栈+离线+扫描线+树状数组区间修改区间查询
题目描述 给出一个序列,多次询问一个区间的所有子区间最小值之和. 输入 输入文件的第一行包含两个整数n和q,分别代表序列长度和询问数.接下来一行,包含n个整数,以空格隔开,第i个整数为ai,即序列第i ...
- 【BZOJ3488】[ONTAK2010]Highways 扫描线+树状数组
[BZOJ3488][ONTAK2010]Highways Description 给一棵n个点的树以及m条额外的双向边q次询问,统计满足以下条件的u到v的路径:恰经过一条额外的边不经过树上u到v的路 ...
- 【BZOJ4009】[HNOI2015]接水果 DFS序+整体二分+扫描线+树状数组
[BZOJ4009][HNOI2015]接水果 Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, ...
随机推荐
- SGU 194 Reactor Cooling 无源汇带上下界可行流
Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...
- effctive C++ 读书笔记 条款 16
条款16 成对使用new和delete时要採取同样形式 #include <iostream> #include <string> using namespace std; / ...
- configuration类详解
hadoop中,组件配置是由Hadoop的Configuration的一个实例实现.(在源码包的org.apache.hadoop.conf中可以找到)先上个类图:这只是部分的,Configuraat ...
- MFC中CAsyncSocket和CSocket
原文链接:https://blog.csdn.net/libaineu2004/article/details/40395917 摘要部分重点: 1.CAsyncSocket类逐个封装了WinSock ...
- boogo08---中间件
package main //中间件1:只允许特定host请求过来 import ( "fmt" "net/http" ) //SingleHost是一个中间件 ...
- java包和javax包的区别
基本类库和扩展类库 一般的lang,util都放在java.包 servlet放在javax包 以前sun把java中的叫核心库,把javax中的叫扩展库.现在sun已经把java和javax中的都叫 ...
- POJ3680 Intervals —— 区间k覆盖问题(最小费用流)
题目链接:https://vjudge.net/problem/POJ-3680 Intervals Time Limit: 5000MS Memory Limit: 65536K Total S ...
- Pycharm中如何安装python库
1首先打开pycharm工具,选择File中的Setting选项,如下图所示 2在打开的setting界面中我们点击python的解释器,你会看到很多导入的第三方库,如下图所示,点击最右边的加号 3在 ...
- [Selenium] Automation Test Manual(Selenium)
http://www.cnblogs.com/puresoul/p/3483055.html http://www.360doc.com/content/14/0913/10/13497042_409 ...
- maven(二)创建一个maven的web项目中解决Cannot change version of project facet Dynamic web module to 2.5
我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一 ...