题意:自行脑补
做法:直接开权值那么多的二维树状数组暴力。
Code:
#include <cstdio> #include <cctype> #include <iostream> #include <algorithm> using namespace std; inline int getc() { static const int L = 1 << 15; static char buf[L], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, L, stdin); if (S == T) return EOF; } return *S++; } inline int getint() { int c; while(!isdigit(c = getc())); int tmp = c - '0'; while(isdigit(c = getc())) tmp = (tmp << 1) + (tmp << 3) + c - '0'; return tmp; } int A[101][301][301], w[301][301]; int n, m; void modify(int c, int x, int y, int add) { int t; for(; x <= n; x += x & -x) { for(t = y; t <= m; t += t & -t) A[c][x][t] += add; } } int get(int c, int x, int y) { int res = 0, t; for(; x; x -= x & -x) { for(t = y; t; t -= t & -t) res += A[c][x][t]; } return res; } int main() { n = getint(); m = getint(); register int i, j; int x; for(i = 1; i <= n; ++i) for(j = 1; j <= m; ++j) { x = getint(); w[i][j] = x; modify(x, i, j, 1); } int Q = getint(); int ope, x1, y1, x2, y2, c; while(Q--) { ope = getint(); if (ope == 1) { x1 = getint(), y1 = getint(), c = getint(); modify(w[x1][y1], x1, y1, -1); modify(w[x1][y1] = c, x1, y1, 1); } else { x1 = getint(), x2 = getint(), y1 = getint(), y2 = getint(); c = getint(); printf("%d\n", get(c, x2, y2) - get(c, x1 - 1, y2) - get(c, x2, y1 - 1) + get(c, x1 - 1, y1 - 1)); } } return 0; }
时间: 2024-12-15 04:32:28