【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. hdu-2837 Calculation---指数循环节

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2837 题目大意: 已知f(0) = 1,0^0 =1,[注意,0的其他任意次方为0,虽然题没有直接给 ...

  2. Cloud Tool 小探索

    Google Apps不用多说. Google drive免费提供15GB的容量. Microsoft Windows Live感觉功能上和google相比无亮点和优势. SkyDrive免费提供7G ...

  3. git 比较不同版本文件的差异

    Git 比较不同版本文件差异的常用命令格式: git diff 查看尚未暂存的文件更新了哪些部分 git diff filename 查看尚未暂存的某个文件更新了哪些 git diff –cached ...

  4. php中文正则匹配

    今天接到一个需求,用户昵称系统需要将昵称输入的字符类型限定为 中文,英文,数字, -,_ 显然这个应该用正则来实现,那么最终的规则是怎么样的呢?示例代码如下: <?php $str = '我爱北 ...

  5. MySQL 8.0.13的使用心得

    今天在阿里云上安装了最新版的MySQL,把碰到的一些问题总结下 1.导入从另一台服务器dump的.sql,出现如下提示: ERROR at line xxx: Unknown command '\\' ...

  6. js的匿名函数与自定义函数

    //匿名方法,会执行,自己调用自己 (function () { console.log(window.innerHeight); })(); (function () { console.log(w ...

  7. oracle sqldrl命令与以及ctl文件

    具体操作如下: 第一步:先编辑好数据控制文件 xx.ctl,如test.ctl options(skip=1)   --跳过第一行(看实际情况) load data infile 'C:\Users\ ...

  8. iOS原生混合RN开发最佳实践

    iOS原生混合RN开发详解 做过原生iOS开发或者Android开发的同学们肯定也都了解Hybrid,有一些Hybrid的开发经验,目前我们企业开发中运用最广泛的Hybrid App技术就是原生与H5 ...

  9. 【js】深拷贝和浅拷贝区别,以及实现深拷贝的方式

    一.区别:简单点来说,就是假设B复制了A,当修改A时,看B是否会发生变化,如果B也跟着变了,说明这是浅拷贝,如果B没变,那就是深拷贝. 此篇文章中也会简单阐述到栈堆,基本数据类型与引用数据类型,因为这 ...

  10. BZOJ1023: [SHOI2008]cactus仙人掌图(仙人掌dp)

    Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3467  Solved: 1438[Submit][Status][Discuss] Descripti ...