对了但是不太明白
查看原帖
对了但是不太明白
105090
wyl_AC楼主2024/3/10 01:01
#include<bits/stdc++.h>
#define M 100005
#define LL long long
#define Mod 998244353ll
#define INF 1000000000000000000ll
using namespace std;
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
void wt(LL x){
	if(x<10){
		putchar(x+'0');
		return ;	
	}
	wt(x/10);
	putchar(x%10+'0');
	return ;
	
}
void write(LL x){
	if(x<0){
		x=-x;
		putchar('-');
	}
	wt(x);
	return ;
}
struct node{
	LL x,y,z,num,cnt;
	bool operator ==(node tp){
		return x==tp.x&&y==tp.y&&z==tp.z;
	}
}s[M],tp[M];
LL t[M<<1],ans[M];
LL n,m,lim;
bool cmp1(node a,node b){
	return a.x==b.x?(a.y==b.y?a.z<b.z:a.y<b.y):a.x<b.x;
}
bool cmp2(node a,node b){
	return a.y<b.y; 
} 
LL lowbit(LL x){
	return x&(-x);
}
void add(LL k,LL x){
	while(k<=lim){
		t[k]+=x;
		k+=lowbit(k);
	}
	return ;
}
LL query(LL k){
	LL ret=0;
	while(k){
		ret+=t[k];
		k-=lowbit(k);		
	}
	return ret;
}
void cdq(LL l,LL r){
	if(l==r)
		return ;
	LL mid=l+r>>1;
	cdq(l,mid);
	cdq(mid+1,r);
	sort(s+l,s+mid+1,cmp2);
	sort(s+mid+1,s+r+1,cmp2); 
	LL i=l,j=mid+1;
	for(;j<=r;j++){
		for(;i<=mid&&s[i].y<=s[j].y;i++)
			add(s[i].z,s[i].cnt);
		s[j].num+=query(s[j].z);
	}
	for(j=l;j<i;j++)
		add(s[j].z,-s[j].cnt);
}
int main(){
	read(n),read(lim);
	for(int i=1;i<=n;i++)
		read(tp[i].x),read(tp[i].y),read(tp[i].z);
	sort(tp+1,tp+1+n,cmp1);
	for(int i=1;i<=n;i++){
		if(!(tp[i]==tp[i-1]))
			s[++m]=tp[i],s[m].cnt=1;
		else
			s[m].cnt++;
	}
	cdq(1,m);
	for(int i=1;i<=m;i++)
		ans[s[i].num+s[i].cnt-1]+=s[i].cnt;
	for(int i=0;i<n;i++){
		write(ans[i]);
		putchar('\n');
	}
	return 0; 
}	

为啥我cmp1中只比较x也会导致样例错误 这是用来去重的 可是样例没有重复的

2024/3/10 01:01
加载中...