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

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. C++设计模式-Facade模式

    Facade模式 作用:为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 动机 将一个系统划分成为若干个子系统有利于降低系统的复杂性.一 ...

  2. 1不等于1?numeric、decimal、float 和 real 数据类型的区别

    大家有没有在SQL中遇见1不等于1(1<>1)的情形!?下面会有一个例子演示这个情形. 先简单介绍一下标题中的四种数值数据类型. 在T-SQL中,numeric和decimal是精确数值数 ...

  3. IOS :编译时出现的错误 ,希望可以有所帮助

    1."std::ios_base::Init::~Init()", referenced from 答1: 如果出现这样的编译问题,是需要再加进libstdc++.dylib和li ...

  4. SQLServer 事务隔离级别

    MSSQL 事务级别 分类: 数据库2012-12-28 11:17 1050人阅读 评论(0) 收藏 举报 事务 级别 等级优化数据库 一个系统项目做大了,就会遇到性能问题.数据库的优化将是解决性能 ...

  5. Shuffling Machine和双向链表

    1. 双向链表 https://github.com/BodhiXing/Data_Structure 2. Shuffling Machine https://pta.patest.cn/pta/t ...

  6. PgSQL dump 工具

    #!/bin/bash #Auther Sun Ying ##Copy left ##Version: Demo Version ##Basic Compare the datebase change ...

  7. leetcode 190

    190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 4326159 ...

  8. Struts2 XML配置详解

    struts官网下载地址:http://struts.apache.org/   1.    深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1.    包配置: S ...

  9. UDP发送和接收

    发送函数 public bool udpSend(string ip, int port, byte[] data) { Socket socket = new Socket(AddressFamil ...

  10. 安装zabbix报错configure: error: libcurl library not found

    libcurl 和libcurl-devel都已经安装 且大于7.13.1 但还是报错,这时需要在configure 指定curl路径即可 ./configure --prefix=/usr/loca ...