【POJ2482】Stars in Your Window

题面

vjudge

题解

第一眼还真没发现这题居然™是个扫描线

令点的坐标为\((x,y)\)权值为\(c\),则

若这个点能对结果有\(c\)的贡献,必须要矩形左下角的点的范围必须在\(([x,x+w),[y,y+h))\)之间

则按扫描线套路将一个类似矩形的范围拆成线\((x,y1,y2,c)\)、\((x+w,y1,y2,-c)\)(依次表示横坐标、下端点纵坐标、上端点纵坐标、权值)即可

最后注意排序时不但要按\(x\)排,也要按权值排

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_N = 100005;
ll N, W, H;
struct rec { ll x, y, _y, k; } t[MAX_N << 1]; int cnt;
inline bool cmp_x (const rec &a, const rec &b) {
if (a.x == b.x) return a.k < b.k;
else return a.x < b.x;
}
ll X[MAX_N << 2], size = 0;
#define lson (o << 1)
#define rson (o << 1 | 1)
ll mx[MAX_N << 3], tag[MAX_N << 3];
void puttag(int o, ll v) { mx[o] += v, tag[o] += v; }
void pushup(int o) { mx[o] = max(mx[lson], mx[rson]) + tag[o]; }
void build(int o, int l, int r) {
mx[o] = tag[o] = 0;
if (l == r) return ;
int mid = (l + r) >> 1;
build(lson, l, mid); build(rson, mid + 1, r);
}
void modify(int o, int l, int r, int ql, int qr, ll v) {
if (ql <= l && r <= qr) return (void)puttag(o, v);
int mid = (l + r) >> 1;
if (ql <= mid) modify(lson, l, mid, ql, qr, v);
if (qr > mid) modify(rson, mid + 1, r, ql, qr, v);
pushup(o);
}
int main () {
while (scanf("%lld%lld%lld", &N, &W, &H) != EOF) {
cnt = 0; size = 0;
for (int i = 1; i <= N; i++) {
ll x, y, c; scanf("%lld%lld%lld", &x, &y, &c);
t[++cnt].x = x, t[cnt].y = y, t[cnt]._y = y + H, t[cnt].k = c;
t[++cnt].x = x + W, t[cnt].y = y, t[cnt]._y = y + H, t[cnt].k = -c;
X[++size] = x, X[++size] = x + W, X[++size] = y, X[++size] = y + H;
}
sort(&X[1], &X[size + 1]); size = unique(&X[1], &X[size + 1]) - X - 1;
sort(&t[1], &t[cnt + 1], cmp_x);
build(1, 1, size - 1);
ll ans = 0;
for (int i = 1; i <= cnt; i++) {
int l = lower_bound(&X[1], &X[size + 1], t[i].y) - X;
int r = lower_bound(&X[1], &X[size + 1], t[i]._y) - X - 1;
modify(1, 1, size - 1, l, r, t[i].k);
ans = max(ans, mx[1]);
}
printf("%lld\n", ans);
}
return 0;
}

【POJ2482】Stars in Your Window的更多相关文章

  1. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  2. 【POJ2482】Stars in Your Window(线段树,扫描线)

    题意:在二维坐标系中有一些带权值的点,要求用一个长宽指定不能互换的框套住其中的一些,使得它们的权值和最大. n<=10000 x,y<=2^31 思路:首先按X排序,将Y坐标离散化,X坐标 ...

  3. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  4. 【转】mysql8.0 在window环境下的部署与配置

    [转]mysql8.0 在window环境下的部署与配置 今天在阿里云window服务器上配置mysql环境,踩了一些坑,分享出来.需要的朋友可以看看.额,或许有人要吐槽我为什么不在linux上去配置 ...

  5. 【POJ2482】【线段树】Stars in Your Window

    Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw ...

  6. 【POJ 2482】Stars in Your Window

    http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<alg ...

  7. 【转】Js中的window.parent ,window.top,window.self 详解

    [转自]http://blog.csdn.net/zdwzzu2006/article/details/6047632 在应用有frameset或者iframe的页面时,parent是父窗口,top是 ...

  8. 【转】分析器窗口 Profiler window

    转自unity圣典: http://game.ceeger.com/Manual/ProfilerWindow.html http://game.ceeger.com/Manual/Profiler. ...

  9. 【转】Redis安装整理(window平台和Linux平台)

    原文连接:http://zheng12tian.iteye.com/blog/1471726 原文作者:zheng12tian 转载注明以上信息! window平台Redis安装 redis wind ...

随机推荐

  1. stl sort使用不当造成崩溃

    #include <iostream>#include <vector>#include <algorithm>using namespace std; bool ...

  2. cascade rcnn

    在region proposal阶段采用不同的iou. 第一幅图,不同颜色的线是用不同的region proposal的iou阈值,横坐标是region proposal生成的框与gt的原始iou,纵 ...

  3. ASP.NET CORE MVC 2.0 如何在Filter中使用依赖注入来读取AppSettings,及.NET Core控制台项目中读取AppSettings

    问: ASP.NET CORE MVC 如何在Filter中使用依赖注入来读取AppSettings 答: Dependency injection is possible in filters as ...

  4. win764 ping不能用的问题

    1.某日发现,ping突然用不了了 2.百度一搜,有如下解答: 1.右击计算机点属性之后找到系统属性下的环境变量: 2.找到系统变量的"path"之后按“编辑”: 3.变量值前面的 ...

  5. Oracle 11g监听器配置

    Oracle 11g监听器配置 安装好oracle后,出现oracle监听器不能正确使用的问题,先后遇到问题: 1.Oracle ORA-12541:TNS:no listener 2.ORA-285 ...

  6. RAC Cache Fusion Background Processes

    Acdante--每日三省吾身-- . 什么是缓存融合? .缓存融合工作原理? .缓存融合关键进程以及作用?

  7. kendo UI 倒如css 和 js 后 窗口控件上的工具栏图标不显示如何解决

    examples 文档中找到window的例子打开一个 查看其中文件引入 <head>    <title>API</title>    <meta char ...

  8. MVC进行多文件上传

    用mvc做多文件的上传和保存到本地,大致流程就是,前台通过form表单提交多文件,Controller接受到文件流,将文件流保存到本地 然后将保存地址 存到数据库中. 将文件通过from提交 < ...

  9. C++笔记008:C++对C的扩展——命名空间 namespace基础

    原创笔记,转载请注明出处! 点击[关注],关注也是一种美德~ 第一, 命名空间的意义 命名空间是ANSIC++引入的可以由用户命名的作用域,用来处理程序中常见的同名冲突. 我认识两位叫“A”的朋友,一 ...

  10. python3爬取全站美眉图片

    爬取网站:https://www.169tp.com/xingganmeinv 该网站美眉图片有数百页,每页24张,共上万张图片,全部爬取下来 import urllib.request import ...