首页 > 代码库 > BZOJ1452 [JSOI2009]Count Solution
BZOJ1452 [JSOI2009]Count Solution
题意:自行脑补
做法:直接开权值那么多的二维树状数组暴力。
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; }
BZOJ1452 [JSOI2009]Count Solution
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。