BZOJ1052【树状数组】

来源:互联网 发布:淘宝店内容营销 编辑:程序博客网 时间:2024/06/05 07:49
/* I will wait for you*/        #include <cstdio>    #include <cstdlib>    #include <cstring>    #include <cmath>    #include <ctime>    #include <algorithm>    #include <iostream>    #include <fstream>    #include <vector>    #include <queue>    #include <deque>    #include <map>    #include <set>    #include <string>    #define make make_pair    #define fi first    #define se second        using namespace std;        typedef long long ll;    typedef unsigned long long ull;    typedef pair<int,int> pii;        const int maxn = 1000010;    const int maxm = 310;    const int maxs = 30;    const int inf = 0x3f3f3f3f;    const int P = 1000000007;    const double error = 1e-9;    inline int read()    {        int x = 0, f = 1; char ch = getchar();        while (ch <= 47 || ch >= 58)            f = (ch == 45 ? -1 : 1), ch = getchar();        while (ch >= 48 && ch <= 57)            x = x * 10 + ch - 48, ch = getchar();        return x * f;  }    struct BIT{int s[maxm][maxm];void insert(int x, int y){for (int i = x; i < maxm; i += i & -i)for (int j = y; j < maxm; j += j & -j)s[i][j] += 1;}void erase(int x, int y){for (int i = x; i < maxm; i += i & -i)for (int j = y; j < maxm; j += j & -j)s[i][j] -= 1;}int sum(int x, int y) {int tmp = 0;for (int i = x; i >= 1; i -= i & -i)for (int j = y; j >= 1; j -= j & -j)tmp += s[i][j];return tmp;}int query(int xl, int yl, int xr, int yr) {int tmp = 0;tmp += sum(xr, yr) + sum(xl - 1, yl - 1);tmp -= sum(xr, yl - 1) + sum(xl - 1, yr);return tmp;}} num[105];int prev[maxm][maxm];int main(){int n = read(), m = read();for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)prev[i][j] = read(), num[prev[i][j]].insert(i, j);int q = read();while (q--) {int t = read();if (t == 1) {int x = read(), y = read(), s = read();num[prev[x][y]].erase(x, y);prev[x][y] = s;num[prev[x][y]].insert(x, y);}if (t == 2) {int xl = read(), xr = read(), yl = read(), yr = read(), s = read();printf("%d\n", num[s].query(xl, yl, xr, yr));}}return 0;}  

0 0