rt
题目传送门:
https://www.luogu.com.cn/problem/P1502
不论怎么改都是WA,只AC第一个点
感谢巨佬们
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+100,M=5*N;
int n,w,h,T;
map <int,int>m;
int mp=0;
class Tree{
public:
int a[M];
int t[M];
int tag[M];
void init(int p,int l,int r){
if(l==r){
t[p]=a[l];
return;
}
int mid=(l+r)/2;
init(p*2,l,mid);
init(p*2+1,mid+1,r);
t[p]=max(t[p*2],t[p*2+1]);
}
void pushdown(int p,int l,int r){
t[p*2]+=tag[p];
t[p*2+1]+=tag[p];
tag[p*2]+=tag[p];
tag[p*2+1]+=tag[p];
tag[p]=0;
}
void update(int xl,int xr,int v,int p,int l,int r){
pushdown(p,l,r);
if(l>=xl and r<=xr){
t[p]+=v;
tag[p]+=v;
return;
}
int mid=(l+r)/2;
if(xl<=mid) update(xl,xr,v,p*2,l,mid);
if(mid<xr) update(xl,xr,v,p*2+1,mid+1,r);
t[p]=max(t[p*2],t[p*2+1]);
}
int query(int xl,int xr,int p,int l,int r){
pushdown(p,l,r);
if(l>=xl and xr>=r) return t[p];
int mid=(l+r)/2;
int ret=0;
if(xl<=mid) ret=max(ret,query(xl,xr,p*2,l,mid));
if(xr>mid) ret=max(ret,query(xl,xr,p*2+1,mid+1,r));
return ret;
}
void clear(){
memset(a,0,sizeof(a));
memset(t,0,sizeof(t));
memset(tag,0,sizeof(tag));
}
};
Tree t;
struct Star{
int x,yy,y,l;
};
Star s[N];
bool cmp(Star a,Star b){
return (a.x==b.x?a.yy<b.yy:a.x<b.x);
}
bool cmp2(Star a,Star b){
return a.yy<b.yy;
}
int g[N];
signed main(){
cin>>T;
for(int o=1;o<=T;o++){
mp=0;
memset(s,0,sizeof(s));
memset(g,0,sizeof(g));
m.clear();
t.clear();
cin>>n>>w>>h;
w--;h--;
for(int i=1;i<=n;i++){
cin>>s[i].x>>s[i].yy>>s[i].l;
}
sort(s+1,s+1+n,cmp2);
int r=1;
for(int l=1;l<=n;l++){
while(s[r].yy<=s[l].yy+h and r<n) ++r;
g[l]=r;
}
for(int i=1;i<=n;i++){
if(m[s[i].yy]==0) m[s[i].yy]=++mp;
s[i].y=m[s[i].yy];
}
sort(s+1,s+1+n,cmp);
t.init(1,1,n*2);
int l=1;
r=1;
int ans=0;
for(int u=1;u<=n;u++){
while(s[l].x<s[u].x-w and l<=r) t.update(s[l].y,s[g[l]].y,-s[l].l,1,1,n*2),l++;
while(s[r].x<=s[u].x and r<=n) t.update(s[r].y,s[g[r]].y,s[r].l,1,1,n*2),r++;
ans=max(ans,t.query(1,n*2,1,1,n*2));
}
cout<<ans<<endl;
}
return 0;
}