求调
查看原帖
求调
117307
hyj0824楼主2023/7/17 22:56
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using LL = unsigned int;
using ull = unsigned long long;
using ld = long double;

inline int read() {
	int x = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c ^ 48), c = getchar());
	return x;
}

const int maxn = 1e6 + 10;

inline int lowbit(int x) {
	return (-x) & x;
}

int n,m,k;
LL a[maxn],t[maxn];
void modi(int pos,LL val) {
	for(int i=pos; i<=n; i+=lowbit(i)) {
		t[i]+=val-a[pos];
	}
	a[pos]=val;
}
LL sum(int pos) {
	LL ans=0;
	for(int i=pos; i; i-=lowbit(i)) {
		ans+=t[i];
	}
	return ans;
}
// 滚动树状数组存的是一行所有点的上下 C 的乘积 ,每个下标表示该列
// 由此可以log计算区间和,用完更新该列(点)的成绩

int u[maxn],d[maxn];  // 一列
int l[maxn],r[maxn];  // 一行
// 对于一点可以快速求出上下左右点的个数

// 空地不产生影响,可以离散化
std::vector<int> x,y;
struct Tree {
	int x,y;
	bool operator<(const Tree& b) const {
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
} tr[maxn];


LL c[maxn][14],ans;
void init() {
	c[1][0]=c[1][1]=1;
	LL top = std::max(m,n);
	for(int i=2; i<=top; i++) {
		c[i][0]=1;
		for(int j=1; j<=k; j++) {
			c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
}

signed main() {
	int nn=read(),mm=read();
	int q=read();
//	x.push_back(0),y.push_back(0);
	for(int i=1; i<=q; i++) {
		tr[i].x=read(),tr[i].y=read();
		x.push_back(tr[i].x);
		y.push_back(tr[i].y);
	}
	std::sort(x.begin(),x.end());
	std::sort(y.begin(),y.end());
	x.erase(std::unique(x.begin(),x.end()),x.end());
	y.erase(std::unique(y.begin(),y.end()),y.end());
	n=x.size(),m=y.size();
	k=read();
	init(); // combine  c_i^k
	for(int i=1; i<=q; i++) {
		tr[i].x=std::lower_bound(x.begin(),x.end(),tr[i].x)-x.begin()+1;
		tr[i].y=std::lower_bound(y.begin(),y.end(),tr[i].y)-y.begin()+1;
		r[tr[i].x]++,d[tr[i].y]++; // 即为(1,1)的状态
	}
	std::sort(tr+1,tr+1+q);

	int px=0,py=0;
	for(int i=1; i<=q; i++) {
		int x=tr[i].x,y=tr[i].y;
		if(px==x) {
//			cout<<c[l[px]][k]*c[r[px]][k]<<" | "<<sum(y-1)-sum(py)<<'\n';
			ans += c[l[px]][k]*c[r[px]][k] * (sum(y-1)-sum(py));
		}
		u[y]++,d[y]--;
		l[x]++,r[x]--;
//		cout<<"now "<<x<<","<<y<<" "<<c[u[y]][k]*c[d[y]][k]<<'\n';
//		cout<<u[y]<<" and "<<d[y]<<'\n';
		modi(y,c[u[y]][k]*c[d[y]][k]);
		px=x,py=y;
	}
	if(ans >= 2147483648)ans -= 2147483648;
	cout << ans;
	return 0;
}
2023/7/17 22:56
加载中...