BZOJ3476 : [Usaco2014 Mar]The Lazy Cow
旋转坐标系后转化为正方形,$x'=x+y$,$y'=x-y+1000001$,$k'=2k-1$
两根扫描线从左往右扫
f[i]表示y坐标下边界为i时的价值和
每次加入/删除一个点等价于一段区间加减
然后查询全局最大值
线段树维护扫描线之间的点
#include<cstdio>
#include<algorithm>
const int E=1000001,N=E*2-1,M=N*4+10;
struct P{int x,y,g;}a[100010];
inline bool cmp(P a,P b){return a.x<b.x;}
int n,m,k,i,j,x,y,ans,v[M],tag[M];
inline void add1(int x,int p){v[x]+=p,tag[x]+=p;}
void add(int x,int a,int b,int c,int d,int p){
if(c<=a&&b<=d){add1(x,p);return;}
if(tag[x])add1(x<<1,tag[x]),add1(x<<1|1,tag[x]),tag[x]=0;
int mid=(a+b)>>1;
if(c<=mid)add(x<<1,a,mid,c,d,p);
if(d>mid)add(x<<1|1,mid+1,b,c,d,p);
v[x]=v[x<<1]>v[x<<1|1]?v[x<<1]:v[x<<1|1];
}
int main(){
scanf("%d%d",&n,&k);k=k*2+1;
for(i=1;i<=n;i++)scanf("%d%d%d",&a[i].g,&x,&y),a[i].x=x+y,a[i].y=x-y+E;
std::sort(a+1,a+n+1,cmp);
for(i=j=1;i<=n;i++){
while(a[i].x-a[j].x+1>k)add(1,1,N,a[j].y-k+1,a[j].y,-a[j].g),j++;
add(1,1,N,a[i].y-k+1,a[i].y,a[i].g);
if(ans<v[1])ans=v[1];
}
return printf("%d",ans),0;
}
BZOJ3476 : [Usaco2014 Mar]The Lazy Cow的更多相关文章
- BZOJ_3476_[Usaco2014 Mar]The Lazy Cow_扫描线+切比雪夫距离
		BZOJ_3476_[Usaco2014 Mar]The Lazy Cow_扫描线+切比雪夫距离 Description It's a hot summer day, and Bessie the c ... 
- BZOJ 3477: [Usaco2014 Mar]Sabotage( 二分答案 )
		先二分答案m, 然后对于原序列 A[i] = A[i] - m, 然后O(n)找最大连续子序列和, 那么此时序列由 L + mx + R组成. L + mx + R = sum - n * m, s ... 
- [Usaco2014 Mar]Sabotage
		[Usaco2014 Mar]Sabotage 题目 Farmer John"s arch-nemesis, Farmer Paul, has decided to sabotage Far ... 
- BZOJ3479: [Usaco2014 Mar]Watering the Fields
		3479: [Usaco2014 Mar]Watering the Fields Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 81 Solved: ... 
- BZOJ 3479: [Usaco2014 Mar]Watering the Fields( MST )
		MST...一开始没注意-1结果就WA了... ---------------------------------------------------------------------------- ... 
- BZOJ_3477_[Usaco2014 Mar]Sabotage_二分答案
		BZOJ_3477_[Usaco2014 Mar]Sabotage_二分答案 题意: 约翰的牧场里有 N 台机器,第 i 台机器的工作能力为 Ai.保罗阴谋破坏一些机器,使得约翰的工作效率变低.保罗可 ... 
- bzoj 3479: [Usaco2014 Mar]Watering the Fields
		3479: [Usaco2014 Mar]Watering the Fields Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved ... 
- BZOJ_3479_[Usaco2014 Mar]Watering the Fields_Prim
		BZOJ_3479_[Usaco2014 Mar]Watering the Fields_Prim Description Due to a lack of rain, Farmer John wan ... 
- 【二分  贪心】bzoj3477: [Usaco2014 Mar]Sabotage
		科学二分姿势 Description Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's mi ... 
随机推荐
- Lucene4.3开发之分词器总结
			Lucene4.3开发之分词器总结 http://java.chinaitlab.com/tools/940011.html 
- Django  authentication 使用方法
			转自 : https://docs.djangoproject.com/en/1.8/topics/auth/customizing/ 
- ios抓包官方文档
			OS X Programs OS X supports a wide range of packet trace programs, as described in the following sec ... 
- MVC数据验证
			深入浅出 MVC 数据验证 2.0 [附演示源码] 今天在这里给大家介绍一下MVC的数据验证框架. 在1.0版中,很多朋友提出了怎么使用客户端验证,今天找了一些资料,发现了客户端验证的方法. 1.MV ... 
- iOS7 中的statusbar的隐藏和样式更改
			ios7以前,如果想要隐藏statusbar,需要用到[UIApplicationsharedApplication].statusBarHidden = YES; 或者在plist文件中设定Stat ... 
- Java for LeetCode 164 Maximum Gap
			Given an unsorted array, find the maximum difference between the successive elements in its sorted f ... 
- google maps js v3 api教程(2) -- 在地图上添加标记
			原文链接 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 我们在创建地图 ... 
- cut  mysqladmin
			[root@86 ~]# mysqladmin -uroot -p123456 -S /tmp/mysql.sock status Uptime: 112403 Threads: 17 Questio ... 
- 最简单的ngResource使用样码
			用来实现基本的RESTful风格的API. 后端用django rest_framework(DRF),前端用AngularJS. app.js var prismVersion = angular. ... 
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
			Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ... 
