线段树求调,太弱了连维护区间最值都不会呜呜呜~
查看原帖
线段树求调,太弱了连维护区间最值都不会呜呜呜~
1318046
Yuukiyo楼主2024/9/23 08:52
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#define mid (l+r>>1)
#define lc u<<1
#define rc u<<1|1
using namespace std;
typedef long long LL;
const int N=1e5+5;
int n,m,x,y,v,ma[N*4],tag[N*4],ans;
struct line{
    int l,r,y,v;
    bool operator<(const line& b) const{return y!=b.y?y<b.y:v>b.v;}
}s[N*4];
inline int rd() {
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
void change(int u,int l,int r,int x,int y,int v,int s) {
    if (x<=l&&r<=y) {ma[u]+=v+s;tag[u]+=v;return;}
    if (x<=mid) change(lc,l,mid,x,y,v,s+tag[u]);
    if (y>mid) change(rc,mid+1,r,x,y,v,s+tag[u]);
    ma[u]=max(ma[lc],ma[rc]);
}
int main() {
    n=rd(),m=rd();
    for (int i=1;i<=n;++i) {
        x=rd()+1,y=rd()+1,v=rd();
        s[i]={x,x+m-1,y,v};s[i+n]={x,x+m-1,y+m-1,-v};
    }
    sort(s+1,s+2*n+1);
    for (int i=1;i<=2*n;++i) {
        int l=s[i].l,r=s[i].r,v=s[i].v;
        change(1,1,N,l,r,v,0);
        ans=max(ans,ma[1]);
    }
    printf("%d",ans);
    return 0;
}

评测记录

2024/9/23 08:52
加载中...