【POJ2482】Stars in Your Window
【POJ2482】Stars in Your Window
题面
题解
第一眼还真没发现这题居然™是个扫描线
令点的坐标为\((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的更多相关文章
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- 【POJ2482】Stars in Your Window(线段树,扫描线)
题意:在二维坐标系中有一些带权值的点,要求用一个长宽指定不能互换的框套住其中的一些,使得它们的权值和最大. n<=10000 x,y<=2^31 思路:首先按X排序,将Y坐标离散化,X坐标 ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- 【转】mysql8.0 在window环境下的部署与配置
[转]mysql8.0 在window环境下的部署与配置 今天在阿里云window服务器上配置mysql环境,踩了一些坑,分享出来.需要的朋友可以看看.额,或许有人要吐槽我为什么不在linux上去配置 ...
- 【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 ...
- 【POJ 2482】Stars in Your Window
http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<alg ...
- 【转】Js中的window.parent ,window.top,window.self 详解
[转自]http://blog.csdn.net/zdwzzu2006/article/details/6047632 在应用有frameset或者iframe的页面时,parent是父窗口,top是 ...
- 【转】分析器窗口 Profiler window
转自unity圣典: http://game.ceeger.com/Manual/ProfilerWindow.html http://game.ceeger.com/Manual/Profiler. ...
- 【转】Redis安装整理(window平台和Linux平台)
原文连接:http://zheng12tian.iteye.com/blog/1471726 原文作者:zheng12tian 转载注明以上信息! window平台Redis安装 redis wind ...
随机推荐
- (转)tcp的半连接与完全连接队列
队列及参数 tcp-sync-queue-and-accept-queue-small.jpg server端的半连接队列(syn队列) 在三次握手协议中,服务器维护一个半连接队列,该队列为每个客 ...
- Webpack笔记(三)——一款破产版脚手架的开发
前些天一直在学习入门Webpack,后来尝试了自己搭建一下一个简单的React开发环境,后来就在想可不可以自己写一个简单的脚手架,以免每次搭建一个简单的开发环境都需要自己一个个的配置,这样很麻烦,使用 ...
- 连接IBM MQ原因码报2035的错误解决办法
我们的系统使用了ibm mq,用户用来向国家局上报文件和接收文件,前几天用户说上报一直不成功.由于 开发这块程序的人已经辞职了,我觉定在我的机器部署一套,研究一下.我的思路: 在我的机器上安装mq,建 ...
- Linux硬盘扩容
1.安装gparted分区工具 2.从虚拟机设置新的虚拟硬盘 3.挂载分区 sudo mount -t ext4 /dev/sdb1 /home/zhoushuo/zsdf -hsudo chmod ...
- Volecity模板引擎学习笔记
转自:https://blog.csdn.net/reggergdsg/article/details/50937433 最近项目中用到了volecity模板,这里做一下笔记,学习中...相比较 Fr ...
- tomcat解析
tomat是一个servlet容器,来处理http请求.在平时的使用中我们都会再浏览器中输入http地址来访问服务资源,比如格式http://host[":"port][abs_p ...
- 20181029noip模拟赛T1
1.借书 [问题描述] Dilhao一共有n本教科书,每本教科书都有一个难度值,他每次出题的时候都会从其中挑两本教科书作为借鉴,如果这两本书的难度相差越大,Dilhao出的题就会越复杂,也就是说,一道 ...
- C++笔记006:关于类的补充
原创笔记,转载请注明出处! 点击[关注],关注也是一种美德~ 关于类的补充: 类是一个数据类型(固定大小内存块的别名),定义一个类,是一个抽象的概念,不会给你分配内存,用数据类型定义变量的时候,才会分 ...
- 竞赛题解 - [CF 1080D]Olya and magical square
Olya and magical square - 竞赛题解 借鉴了一下神犇tly的博客QwQ(还是打一下广告) 终于弄懂了 Codeforces 传送门 『题目』(直接上翻译了) 给一个边长为 \( ...
- Xdebug 备注
安装步骤: 查看自己的环境是否已安装 Xdebug ,查看方法:使用phpinfo(),搜索 Xdebug 如果没有 如图: 如果没有:下一步确定你的PHP版本信息: Xdebug下载地址 https ...