神犇就是厉害,从小就会暴力过题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10000+5;
struct tri{
int x,y,d,l,r;
bool operator < (const tri &rhs)const{
return y<rhs.y;
}
}t[N];
int pre[N],next[N];
void del(int x){
pre[next[x]]=pre[x];
next[pre[x]]=next[x];
}
void ins(int x,int y){
pre[next[x]]=y;
next[y]=next[x];
pre[y]=x;
next[x]=y;
}
int head,tail,nowh;
bool ins(int x){
if(!t[x].d)return false;
for(int i=next[head];i!=tail;i=next[i])
if(t[i].x<=t[x].x&&t[x].x+t[x].d-1<=t[i].x+t[i].d-1-(t[i].d-nowh))return false;
ins(head,x);
return true;
}
int cover[N*100];
int main(){
//freopen("a.in","r",stdin);
int n;scanf("%d",&n);
int mx=0;
for(int i=1;i<=n;i++){
scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].d);
mx=max(mx,t[i].y+t[i].d);
t[i].l=t[i].x;
t[i].r=t[i].x+t[i].d-1;
}
sort(t+1,t+1+n);
int ans=0;
head=0;tail=n+1;
pre[next[head]=tail]=head;
int last=0,j=1;
for(int i=t[1].y;i<=mx;i++){
int now=last;
for(int k=next[head];k!=tail;k=next[k]){
cover[t[k].r]--;
if(!cover[t[k].r])now--;
t[k].r--;
if(t[k].r<t[k].l)del(k);
}
ans+=now+last;
while(j<=n&&t[j].y==i){
if(ins(j)){
for(int k=t[j].x;k<t[j].x+t[j].d;k++){
if(!cover[k])now++;
cover[k]++;
}
}
j++;
}
last=now;
}
printf("%.1lf\n",double(ans)/2.0);
return 0;
}