陌上开花,求调,码风简洁,老玩家回归
查看原帖
陌上开花,求调,码风简洁,老玩家回归
557781
ruojiyz楼主2024/7/10 15:32

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

const int N = 1e5 + 5;

int n, mx, id;
struct V
{
	int a, b, c, cnt;
} xx[N], x[N];
int f[N], c[N << 1], ans[N];

bool cmp1(V u, V v) 
{ 	
	if(u.a != v.a)
		return u.a < v.a;
	if(u.b != v.b)
		return u.b < v.b;
	return u.c < v.c;
}
bool cmp2(V u, V v) 
{
	if(u.b != v.b)
		return u.b < v.b;
	return u.c < v.c;
}

void add(int x, int v)
{
	while(x <= mx)
	{
		c[x] += v;
		x += (x & -x);
	}
}	

int query(int x)
{
	int res = 0;
	while(x)
	{
		res += c[x];
		x -= (x & -x); 
	}
	return res;
}

void solve(int l, int r)
{
	if(l == r) return;
	int mid = (l + r) >> 1;
	solve(l, mid);
	solve(mid + 1, r);
	sort(x + 1 + l, x + 1 + mid, cmp2);
	sort(x + 1 + mid + 1, x + 1 + r, cmp2);
	int i = l, j = mid + 1; 
	while(j <= r)
	{
		while(i <= mid && x[i].b <= x[j].b) 
			add(x[i].c, x[i].cnt), i ++;
		f[j] += query(x[j].c); j ++;
	}
	for(j = l ; j < i ; j ++)
		add(x[j].c, -x[j].cnt);
	return;
}

int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> mx;
	for(int i = 1 ; i <= n ; i ++)
		cin >> xx[i].a >> xx[i].b >> xx[i].c;
	sort(xx + 1, xx + 1 + n, cmp1);
	for(int i = 1, j = 0 ; i <= n ; i ++)
	{
		while(xx[j + 1].a == xx[i].a && xx[j + 1].b == xx[i].b && xx[j + 1].c == xx[i].c) j ++;
		x[ ++ id] = {xx[i].a, xx[i].b, xx[i].c, j - i + 1};
	}

	solve(1, id);
	
	for(int i = 1 ; i <= id ; i ++)
		ans[f[i]] += x[i].cnt;
	for(int i = 0 ; i < n ; i ++)
		cout << ans[i] << "\n";

	return 0;
}
2024/7/10 15:32
加载中...