记录编号 582327 评测结果 AAAAAAAAAA
题目名称 窗口中的星星 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 2.146 s
提交时间 2023-09-09 16:20:22 内存使用 15.66 MiB
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
const int N = 1e5+10; 
int n,w,h;
struct T{
    int l,r;
    int ma,la;
    #define l(x) t[x].l
    #define r(x) t[x].r
    #define ma(x) t[x].ma
    #define la(x) t[x].la
}t[N<<2];
struct made{
    int ed;
    int x,y1,y2;
    made(){}
    made(int ed,int x,int y1,int y2):x(x),ed(ed),y1(y1),y2(y2){}
    bool operator < (const made& p)const{
        return x < p.x;
    }
}line[N<<1];
int shu[N<<1];
int cnt,ans;
void first_(){
    cnt = 0,ans = 0;
    memset(line,0,sizeof(line));
    memset(shu,0,sizeof(shu));
    memset(t,0,sizeof(t));
}
void build(int x,int l,int r){
    l(x) = l,r(x) = r;
    if(l == r)return;
    int mid = (l + r) >> 1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
}
void pushdown(int x){
    if(la(x)){
        ma(x<<1) += la(x);
        ma(x<<1|1) += la(x);
        la(x<<1) += la(x);
        la(x<<1|1) += la(x);
        la(x) = 0;
    }
    
}
void add(int x,int l,int r,int ed){
    if(l <= l(x) && r(x) <= r){
        ma(x) += ed;
        la(x) += ed;
        pushdown(x);
        return;
    }
    pushdown(x);
    int mid = (l(x) + r(x)) >> 1;
    if(mid >= l)add(x<<1,l,r,ed);
    if(mid < r)add(x<<1|1,l,r,ed);
    ma(x) = max(ma(x<<1),ma(x<<1|1));
}
int main(){
    freopen("starswin.in","r",stdin);
    freopen("starswin.out","w",stdout);
    while(scanf("%d%d%d",&n,&w,&h) == 3){
        first_();
        for(int i = 1;i <= n;i++){
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            cnt++;
            shu[cnt] = y,line[cnt] = made(z,x,y,y+h);
            cnt++;
            shu[cnt] = y+h,line[cnt] = made(-z,x+w,y,y+h);
        }
        sort(shu+1,shu+1+cnt);
        sort(line+1,line+1+cnt);
        int m = unique(shu+1,shu+1+cnt) - (shu+1);
        build(1,1,m-1);
        for(int i = 1;i <= cnt;i++){
            int l = lower_bound(shu+1,shu+1+m,line[i].y1) - shu;
            int r = lower_bound(shu+1,shu+1+m,line[i].y2) - shu;
            add(1,l,r-1,line[i].ed);
            if(line[i].x != line[i+1].x)ans = max(ans,t[1].ma);
        }
        printf("%d\n",ans);
    }
    
    return 0;
    
}