zoukankan      html  css  js  c++  java
  • bzoj 1452

    二维BIT。。。

    感觉不会树状数组还是不太好。。而且这题用线段树肯定MLE。。

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(int i=l;i<=r;i++)
     3 #define dec(i,l,r) for(int i=l;i>=r;i--)
     4 #define link(x) for(edge *j=h[x];j;j=j->next)
     5 #define mem(a) memset(a,0,sizeof(a))
     6 #define inf 1e9
     7 #define ll long long
     8 #define succ(x) (1<<x)
     9 #define lowbit(x) (x&(-x))
    10 #define NM 300+5
    11 using namespace std;
    12 int read(){
    13     int x=0,f=1;char ch=getchar();
    14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    16     return x*f;
    17 }
    18 int n,m,p,_x,_y,__x,__y,_t,b[NM][NM];
    19 struct bit{
    20     int a[NM][NM];
    21     void upd(int x,int y,int t){
    22         for(int i=x;i<=n;i+=lowbit(i))
    23         for(int j=y;j<=m;j+=lowbit(j))a[i][j]+=t;
    24     }
    25     int sum(int x,int y){
    26         int s=0;
    27         for(int i=x;i;i-=lowbit(i))
    28         for(int j=y;j;j-=lowbit(j))s+=a[i][j];
    29         return s;
    30     }
    31 }g[105];
    32 int main(){
    33     freopen("data.in","r",stdin);
    34     n=read();m=read();
    35     inc(i,1,n)inc(j,1,m)g[b[i][j]=read()].upd(i,j,1);
    36     p=read();
    37     while(p--){
    38         _t=read();
    39         if(_t==1){
    40             _x=read();_y=read();_t=read();
    41             g[b[_x][_y]].upd(_x,_y,-1);
    42             g[b[_x][_y]=_t].upd(_x,_y,1);
    43         }else{
    44             _x=read()-1;__x=read();_y=read()-1;__y=read();_t=read();
    45             printf("%d
    ",g[_t].sum(__x,__y)+g[_t].sum(_x,_y)-g[_t].sum(_x,__y)-g[_t].sum(__x,_y));
    46         }
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    1657: [Usaco2006 Mar]Mooo 奶牛的歌声
    1610: [Usaco2008 Feb]Line连线游戏
    1660: [Usaco2006 Nov]Bad Hair Day 乱发节
    bzoj1207 [HNOI2004]打鼹鼠
    bzoj1046 [HAOI2007]上升序列
    bzoj3594 [Scoi2014]方伯伯的玉米田
    bzoj1878 [SDOI2009]HH的项链
    bzoj1293 [SCOI2009]生日礼物
    bzoj3211 花神游历各国
    bzoj3038 上帝造题的七分钟2
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5186969.html
Copyright © 2011-2022 走看看