跑不动,求调
查看原帖
跑不动,求调
481621
Zhang_Wenjie楼主2024/3/12 13:21

还有,为什么二维数组传参这样做 res += c[i][j] 这里会报错?如果可以用传参写要怎么写?

int query(int *c[N][N], int x, int y)
	{
		int res = 0;
		for (re i = x; i > 0; i -= lowbit(i))
			for (re j = y; j > 0; j -= lowbit(j))
				res += c[i][j];		
		return res;		
	}
#include <bits/stdc++.h>
#define re register int 
using namespace std;
const int N = 3e3 + 10;
int n, m;

struct BIT
{
	int c[N][N];
	
	int lowbit(int x) { return x & -x; }

	void add(int x, int y, int k)
	{
		for (re i = x; i <= n; i += lowbit(i))
			for (re j = y; j <= m; j += lowbit(j))
				c[i][j] += k;
	}

	int query(int x, int y)
	{
		int res = 0;
		for (re i = x; i > 0; i -= lowbit(i))
			for (re j = y; j > 0; j -= lowbit(j))
				res += c[i][j];		
		return res;		
	}

}c0, c1, c2, c3;


inline void change(int x, int y, int k)
{
	c0.add(x, y, k * x * y);
	c1.add(x, y, k * x);
	c2.add(x, y, k * y);
	c3.add(x, y, k);
}

inline int ans(int x, int y)
{
	int res0 = c0.query(x, y);
	int res1 = c1.query(x, y) * (y + 1);
	int res2 = c2.query(x, y) * (x + 1);
	int res3 = c3.query(x, y) * (x * y + x + y + 1);
	
	return res0 - res1 - res2 + res3;
}

inline int sum(int a, int b, int c, int d)
{
	return ans(c, d) - ans(c, b - 1) - ans(a - 1, d) + ans(a - 1, b - 1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	char op;
	int a, b, c, d, k;
	scanf("X %d %d", &n, &m);
	while (~scanf("%c", &op))
	{
		cin >> a >> b >> c >> d;
		if (op == 'L')
		{
			cin >> k;
			change(a, b, k);
			change(a, d + 1, -k);
			change(c + 1, b, -k);
			change(c + 1, d + 1, k);
		}
		else
			cout << sum(a, b, c, d) << '\n';
			
	}
	
	return 0;
}
2024/3/12 13:21
加载中...