CDQ分治求条,样例过不了,玄关
查看原帖
CDQ分治求条,样例过不了,玄关
1073995
Saint_ying_xtf楼主2024/3/23 16:27
// Author: gsczl71
// Copyright (c) 2024 gsczl71 All rights reserved.
// Problem: P3810 【模板】三维偏序(陌上花开)
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3810
// Memory Limit: 500 MB
// Time Limit: 1000 ms
// Date: 2024-03-23 14:15:35

// #pragma GCC optimize(2,3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
#define i128 __int128
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fs first
#define sc second
#define x0 _x0_
#define y1 _y1_
#define endl '\n'
#define re register
#define pb push_back
#define vi vector<int>
#define pq priority_queue
#define mem(a,x) memset((a),(x),sizeof(a))
#define debug puts("AK IOI")
#define sz(s) (int)(s.size())
#define all(a) a.begin(),a.end()
#define rd(l,r) (myrand()%(r-l+1)+l)
#define print(x) {cout<<x<<endl;return;}
#define ctn(e) if(e) continue
#define brk(e) if(e) break
#define rt(e) if(e) return
#define ll_(e) (1ll*(e))
#define For(x,y,z) for(int x = y;x <= z;x++)
#define For_(x,y,z) for(int x = y;x >= z;x--)
using namespace std;
#define int long long
const int mod = 1e9+7;
//const int mod = 998244353;
mt19937 myrand(time(0));
const int inf = 0x3f3f3f3f,N = 2e5+5,M = 1e6+5,K = 3000+5;
const long long linf = 0x3f3f3f3f3f3f3f3f;
int n,k,m;
struct node{int a,b,c;};
struct data{node a;int cnt,ans;};
node a[N];
struct data b[N];
int t[N<<1];
void add(int x,int val){while(x<=k)t[x]+=val,x+=(x&-x);}
int query(int x){int res=0;while(x)res+=t[x],x-=(x&-x);return res;}
bool node_cmp(node a,node b){
	if(a.a != b.a) return a.a<b.a;
	if(a.b != b.b) return a.b<b.b;
	return a.c<b.c;
}bool data_cmp(struct data a,struct data b){
	if(a.a.b != b.a.b) return a.a.b<b.a.b;
	return a.a.c<b.a.c;
}void cdq(int l,int r){
	if(l==r)return ;
	int mid=(l+r)>>1,x=l;
	cdq(1,mid),cdq(mid+1,r);
	sort(b+1,b+1+mid,data_cmp),sort(b+1+mid,b+1+n,data_cmp);
	For(i,mid+1,r){
		while(x<=mid&&b[x].a.b<=b[i].a.b) add(b[x].a.c,b[x].cnt),x++;
		b[i].ans+=query(b[i].a.c);
	}For(i,l,x-1){
		add(b[i].a.c,-b[i].cnt);//清空还原操作
	}
}int ans[N];
void solve(){
	cin>>n>>k;
	For(i,1,n)cin>>a[i].a>>a[i].b>>a[i].c;
	sort(a+1,a+1+n,node_cmp);
	For(i,1,n){
		if(a[i].a!=a[i-1].a||a[i].b!=a[i-1].b||a[i].c!=a[i-1].c) b[++m].a=a[i];
		b[m].cnt++;	
	}
	cdq(1,m);
	For(i,1,m)ans[b[i].ans+b[i].cnt]+=b[i].cnt;
	For(i,1,n)cout<<ans[i]<<endl;
}
signed main(){
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T=1;
//	cin >> T;
	For(_,1,T) solve();
	return 0;
}


2024/3/23 16:27
加载中...