BZOJ1452 [JSOI2009] Count

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1452

Description

Input

Output

 树状数组水题,水到不行

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #define rep(i,l,r) for(int i=l; i<=r; i++)
 6 #define clr(x,y) memset(x,y,sizeof(x))
 7 #define travel(x) for(Edge *p=last[x]; p; p=p->pre)
 8 using namespace std;
 9 const int maxn = 310;
10 inline int read(){
11     int ans = 0, f = 1;
12     char c = getchar();
13     for(; !isdigit(c); c = getchar())
14     if (c == '-') f = -1;
15     for(; isdigit(c); c = getchar())
16     ans = ans * 10 + c - '0';
17     return ans * f;
18 }
19 int n,m,x1,x2,y1,y2,q,f,c,g[maxn][maxn],t[maxn][maxn][110];
20 void modify(int x,int y,int c,int v){
21     for(int i = x; i <= n; i += i & (-i))
22     for(int j = y; j <= m; j += j & (-j))
23     t[i][j][c] += v;
24 }
25 int query(int x,int y,int c){
26     int ret = 0;
27     for(int i = x; i; i -= i & (-i))
28     for(int j = y; j; j -= j & (-j))
29     ret += t[i][j][c];
30     return ret;
31 }
32 int main(){
33     n = read(); m = read(); clr(t,0);
34     rep(i,1,n) rep(j,1,m) g[i][j] = read(), modify(i,j,g[i][j],1);
35     q = read();
36     rep(i,1,q){
37         f = read();
38         if (f == 1){
39             x1 = read(); y1 = read(); c = read();
40             modify(x1,y1,g[x1][y1],-1);
41             g[x1][y1] = c;
42             modify(x1,y1,g[x1][y1],1);
43         }
44         else{
45             x1 = read(); x2 = read(); y1 = read(); y2 = read(); c = read();
46             int ans = query(x2,y2,c) - query(x1-1,y2,c) - query(x2,y1-1,c) + query(x1-1,y1-1,c);
47             printf("%d\n",ans);
48         }
49     }
50     return 0;
51 }
View Code

 

posted on 2016-03-23 13:46  ACMICPC  阅读(211)  评论(0编辑  收藏  举报

导航