奇怪的求助!(调出来同桌吃键盘)
查看原帖
奇怪的求助!(调出来同桌吃键盘)
690160
ask_silently楼主2024/3/11 21:08

下载了测试点1,本地评测过了,放在Luogu在线IDE上就过不了,测试点也不过不了,求调!!!

#include <bits/stdc++.h>
using namespace std;

#define ls p<<1
#define rs p<<1|1

const int N=1000010;

int n,len;
long long xs[2*N],sum;

struct node1{
	long long x_1,x_2,y;
	int val;
}a[2*N];

struct node{
	int l,r,add;
	long long res;
}tr[8*N];

inline int read(){
	int t=0,f=1;
	register char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?(-1):(f),c=getchar();
	while(c>='0'&&c<='9') t=(t<<3)+(t<<1)+(c^48),c=getchar();
	return t*f;
}

bool cmp(node1 x,node1 y){
	return x.y<y.y;
}

void build(int l,int r,int p){
	tr[p]={l,r,0,0};
	if(l==r) return;
	int mid=l+r>>1;
	build(l,mid,ls);
	build(mid+1,r,rs);
}

void pushup(int p){
	if(tr[p].add) tr[p].res=xs[tr[p].r+1]-xs[tr[p].l];
	else tr[p].res=tr[ls].res+tr[rs].res;
}

void update(int p,int l,int r,int x){
	if(tr[p].l>=l&&tr[p].r<=r){
		tr[p].add+=x;
		pushup(p);
		return;
	}
	int mid=tr[p].l+tr[p].r>>1;
	if(l<=mid) update(ls,l,r,x);
	if(r>mid) update(rs,l,r,x);
	pushup(p);
}

int find(long long x){
	int l=1,r=len,mid;
	while(l<r){
		mid=(l+r)/2;
		if(xs[mid]<x) l=mid+1;
		else if(xs[mid]>x) r=mid-1;
		else return mid;
	}
	return l;
}

signed main(){
	n=read();
	for(int i=1,j=0;i<=n;i++){
		a[++j].x_1=read(),a[j].y=read(),a[j].x_2=read(),a[j].val=1,xs[j]=a[j].x_1;
		a[++j].x_1=a[j-1].x_1,a[j].x_2=a[j-1].x_2,a[j].y=read(),a[j].val=-1,xs[j]=a[j].x_2;
	}
	sort(a+1,a+1+2*n,cmp);
	sort(xs+1,xs+1+2*n);
	len=unique(xs+1,xs+1+2*n)-(xs+1);
	build(1,len-1,1);
	for(int i=1;i<2*n;i++){
		int x=find(a[i].x_1),y=find(a[i].x_2)-1;
		update(1,x,y,a[i].val);
		sum+=(a[i+1].y-a[i].y)*tr[1].res;
	}
	cout<<sum<<"\n";
	return 0;
}


2024/3/11 21:08
加载中...