手机屏摔碎了哦凑。


# IO

Input
There are several test cases in the input. The first line of each case contains 3 integers: n, W, H, indicating the number of stars, the horizontal length and the vertical height of the rectangle-shaped window. Then n lines follow, with 3 integers each: x, y, c, telling the location (x, y) and the brightness of each star. No two stars are on the same point.

There are at least 1 and at most 10000 stars in the sky. 1<=W，H<=1000000, 0<=x，y<2^31.

Output
For each test case, output the maximum brightness in a single line.

# 代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MXN 10010
int ll[MXN<<4],rr[MXN<<4],sum[MXN<<4],flag[MXN<<4];
int n,w,h;
int ans;
void build(int id,int l,int r){
ll[id]=l,rr[id]=r,sum[id]=flag[id]=0;
int m=(l+r)>>1,ls=id<<1,rs=ls|1;
if(l!=r){
build(ls,l,m);
build(rs,m+1,r);
}
}
struct line{
double x,l,h,v;
bool end;
line(){}
line(double a,double b,double c,long long e,bool d){x=a,l=b,h=c,end=d,v=e;}
bool operator < (const line& rgt)const{
return x<rgt.x||x==rgt.x&&end;
}
}l[MXN<<2];
long long lcnt,tot;
double dy[MXN<<2];
void input(){
ans=lcnt=tot=0;
for(int i=0;i<n;++i){
int tx,ty,tc;
scanf("%d%d%d",&tx,&ty,&tc);
double tl=ty-h/2.0+0.1;
double th=ty+h/2.0-0.1;
double ttx=tx-w/2.0+0.1;
l[lcnt++]=line(ttx,tl,th,tc,false);
ttx=tx+w/2.0-0.1;
l[lcnt++]=line(ttx,tl,th,tc,true);
dy[tot++]=tl;
dy[tot++]=th;
}
sort(l,l+lcnt);
sort(dy,dy+tot);
tot=unique(dy,dy+tot)-dy;
}
void down(int id);
void add(int id,double l,double r,int v,bool end){
if(flag[id])    down(id);
if(l==dy[ll[id]]&&r==dy[rr[id]]){
flag[id]+=end ? -v : v;
sum[id]+=flag[id];
return;
}
int m=(ll[id]+rr[id])>>1,ls=id<<1,rs=ls|1;
else{
}
sum[id]=max(sum[ls],sum[rs]);
}
void down(int id){
if(ll[id]==rr[id]){
flag[id]=0;
return;
}
int m=(ll[id]+rr[id])>>1,ls=id<<1,rs=ls|1;
flag[id]=0;
}
int query(int id){
if(flag[id]){
down(id);
}
return sum[id];
}
void solve(){
for(int i=0;i<lcnt;++i){
ans=max(query(1),ans);
}
}
int main(){
//freopen("data.txt","r",stdin);
//freopen("ans.txt","w",stdout);
while(scanf("%d%d%d",&n,&w,&h)!=EOF){
input();
build(1,0,tot-1);
solve();
printf("%d\n",ans);
}
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客