代码:
#include <iostream>
using namespace std;
#define int long long
const int N = 1e5 + 5;
int TreeR[N]; //表示行的覆盖情况
int TreeC[N]; //表示列的覆盖情况
int row[N]; //表示当前行是否被覆盖
int col[N]; //表示当前列是否被覆盖
int n, m, k;
int lowbit(int x)
{
return x & (-x);
}
void update(int tree[], int cur, int k, int limit) //单点修改
{
while (cur <= limit)
{
tree[cur] += k;
cur += lowbit(cur);
}
}
int query(int tree[], int cur) //查询
{
int sum = 0;
while (cur > 0)
{
sum += tree[cur];
cur -= lowbit(cur);
}
return sum;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m >> k;
while (k--)
{
int opt;
cin >> opt;
if (opt == 1)
{
int x, y;
cin >> x >> y;
if (row[x]) //若当前行已经被覆盖,直接消除
update(TreeR, x, -1, n);
else //否则加上1
update(TreeR, x, 1, n);
row[x] ^= 1;
if (col[y]) //若当前列已经被覆盖,直接消除
update(TreeC, y, -1, m);
else //否则加上1
update(TreeC, y, 1, m);
col[y] ^= 1;
} else
{
int x, y, u, v;
cin >> x >> y >> u >> v;
int Row = query(TreeR, u) - query(TreeR, x - 1); //计算行的覆盖情况
int Col = query(TreeC, v) - query(TreeC, y - 1); //计算列的覆盖情况
int ans = (u - x + 1) * Row;
ans += (v - y + 1) * Col;
ans -= 2 * Row * Col;
//公式计算
cout << ans << endl;
}
}
return 0;
}