题意:在二维坐标系中有一些带权值的点,要求用一个长宽指定不能互换的框套住其中的一些,使得它们的权值和最大。

n<=10000 x,y<=2^31

思路:首先按X排序,将Y坐标离散化,X坐标用扫描线框定,每个点(x,y)在x中只对y有a[i]的贡献,y+h有-a[i]的贡献,线段树(树状数组更好写)维护最大子段和即可。

 var t:array[..]of record
l,r,s,m:int64;
end;
x,y,c,a,h:array[..]of int64;
n,m,i,j,tt,ww,up,w1,h1:longint;
ans:int64; procedure swap(var x,y:int64);
var t:int64;
begin
t:=x; x:=y; y:=t;
end; procedure qsort(l,r:longint);
var i,j,mid1,mid2:longint;
begin
i:=l; j:=r; mid1:=x[(l+r)>>]; mid2:=y[(l+r)>>];
repeat
while (mid1>x[i])or((mid1=x[i])and(mid2>y[i])) do inc(i);
while (mid1<x[j])or((mid1=x[j])and(mid2<y[j])) do dec(j);
if i<=j then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
swap(a[i],a[j]);
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end; procedure qsort2(l,r:longint);
var i,j:longint;
mid:int64;
begin
i:=l; j:=r; mid:=c[(l+r)>>];
repeat
while mid>c[i] do inc(i);
while mid<c[j] do dec(j);
if i<=j then
begin
swap(c[i],c[j]);
inc(i); dec(j);
end;
until i>j;
if l<j then qsort2(l,j);
if i<r then qsort2(i,r);
end; function max(x,y:int64):int64;
begin
if x>y then exit(x);
exit(y);
end; procedure pushup(p:longint);
var ls,rs:longint;
begin
ls:=p<<; rs:=ls+;
t[p].l:=max(t[ls].l,t[ls].s+t[rs].l);
t[p].r:=max(t[rs].r,t[rs].s+t[ls].r);
t[p].m:=max(t[ls].r+t[rs].l,max(t[ls].m,t[rs].m));
end; procedure update(l,r,x,v,p:longint);
var mid:longint;
begin
if l=r then
begin
t[p].s:=t[p].s+v;
t[p].l:=t[p].s; t[p].r:=t[p].s; t[p].m:=t[p].s;
exit;
end;
mid:=(l+r)>>;
if x<=mid then update(l,mid,x,v,p<<)
else update(mid+,r,x,v,p<<+);
t[p].s:=t[p].s+v;
pushup(p);
end; function hash(x:int64):longint;
var l,r,mid,last:longint;
begin
l:=; r:=up; last:=;
while l<=r do
begin
mid:=(l+r)>>;
if x=h[mid] then begin last:=mid; r:=mid-; end;
if x<h[mid] then r:=mid-;
if x>h[mid] then l:=mid+;
end;
exit(last);
end; begin
assign(input,'poj2482.in'); reset(input);
assign(output,'poj2482.out'); rewrite(output);
while not eof do
begin
readln(n,w1,h1);
if n= then break;
for i:= to n do read(x[i],y[i],a[i]);
qsort(,n);
m:=;
for i:= to n do
begin
inc(m); c[m]:=y[i];
inc(m); c[m]:=y[i]+h1;
end;
qsort2(,m);
up:=; h[]:=c[];
for i:= to m do
if c[i]>c[i-] then
begin
if c[i]=c[i-]+ then begin inc(up); h[up]:=c[i]; end
else
begin
inc(up); h[up]:=c[i-];
inc(up); h[up]:=c[i];
end;
end;
ans:=-maxlongint;
tt:=; ww:=;
while ww<n do
begin
inc(ww);
while (tt<=n)and(x[tt]+w1-<x[ww]) do
begin
update(,up,hash(y[tt]),-a[tt],);
update(,up,hash(y[tt]+h1),a[tt],);
inc(tt);
end;
update(,up,hash(y[ww]),a[ww],);
update(,up,hash(y[ww]+h1),-a[ww],);
ans:=max(ans,t[].m);
end;
writeln(ans);
for i:= to up<< do
begin
t[i].s:=; t[i].l:=; t[i].r:=; t[i].m:=;
end;
end;
close(input);
close(output);
end.

【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. POJ 2482 Stars in Your Window 线段树扫描线

    Stars in Your Window   Description Fleeting time does not blur my memory of you. Can it really be 4 ...

  3. POJ 2482 Stars in Your Window(线段树+扫描线)

    题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...

  4. POJ 2482 Stars in Your Window (线段树区间合并+扫描线)

    这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星 ...

  5. POJ 2482 Stars in Your Window 线段树

    如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...

  6. 【学习笔记】线段树—扫描线补充 (IC_QQQ)

    [学习笔记]线段树-扫描线补充 (IC_QQQ) (感谢 \(IC\)_\(QQQ\) 大佬授以本内容的著作权.此人超然于世外,仅有 \(Luogu\) 账号 尚可膜拜) [学习笔记]线段树详解(全) ...

  7. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  9. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  10. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

随机推荐

  1. java加密算法之AES小记

    jce中提供了加解密的api: 1.首先应该明白AES是基于数据块的加密方式,也就是说,每次处理的数据是一块(16字节),当数据不是16字节的倍数时填充,这就是所谓的分组密码(区别于基于比特位的流密码 ...

  2. C# 6.0 特性

    C#6.0主要提供了一些语法糖,另外还提供了新的编译器Roslyn地址https://github.com/dotnet/roslyn 一下列举几个新增的语法糖: 1.构造一个类: public cl ...

  3. Linux 网络基本配置

    一.Linux网络配置文件 1.  /etc/sysconfig/network-scripts/ifcfg-eth0 文件 在Red Hat系统中,系统网络设备的配置文件保存在/etc/syscon ...

  4. iOS各种开源类库

    KissXml——xml解析库 相关教程:http://www.iteye.com/topic/625849 http://sencho.blog.163.com/blog/static/830562 ...

  5. Kubernetes集群初探

    上文我们在一台虚机上演示了Kubernetes基于redis和docker的guestbook留言簿案例,本文我们将通过配置Kubernetes集群的方式继续深入研究.集群组件安装如下配置. IP N ...

  6. 显示全部select change 异常

    异常信息(异常类型:Genersoft.Platform.Core.Error.GSPException)异常提示:调用方法SelectChange发生异常,详细请看内部异常信息!异常信息:调用方法S ...

  7. JavaBean,POJO,VO,DTO的区别和联系

    JavaBeans A JavaBean is a class that follows the JavaBeans conventions as defined by Sun. Wikipedia ...

  8. mongodb 分组查询

    数据的保存 include_once 'mDB.class.php'; $m=new mDB(); $m->setDB('mydb'); // $m->save('stu',['dept' ...

  9. [HTML]JS全屏代码

    video全屏参考:https://www.thecssninja.com/javascript/fullscreen <!doctype html> <html> <h ...

  10. discuz中方法

    discuz中检验是否是邮箱 function isemail($email) { && strlen($email) <= && preg_match(&quo ...