zoukankan      html  css  js  c++  java
  • BZOJ 1452: [JSOI2009]Count 二维树状数组

    1452: [JSOI2009]Count

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=1452

    Description

    Input

    Output

    Sample Input

    Sample Output

    1
    2

    HINT

     

    题意

    题解:

    裸的二维树状数组

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 301
    #define mod 1001
    #define eps 1e-9
    #define pi 3.1415926
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    int S[101][maxn][maxn];
    int col[maxn][maxn];
    int n,m;
    int lowbit(int x){return x&(-x);}
    void updata(int c[maxn][maxn],int x,int y,int w)
    {
        for(int i=x;i<=n;i+=lowbit(i))
            for(int j=y;j<=m;j+=lowbit(j))
                c[i][j]+=w;
    }
    int sum(int c[maxn][maxn],int x,int y)
    {
        int ans=0;
        for(int i=x;i;i-=lowbit(i))
            for(int j=y;j;j-=lowbit(j))
                ans+=c[i][j];
        return ans;
    }
    
    int solve(int c[maxn][maxn],int x1,int y1,int x2,int y2)
    {
        return sum(c,x2,y2)-sum(c,x2,y1-1)-sum(c,x1-1,y2)+sum(c,x1-1,y1-1);
    }
    
    int main()
    {
        n=read(),m=read();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                int x=read();
                col[i][j]=x;
                updata(S[x],i,j,1);
            }
        }
        int q=read();
        while(q--)
        {
            int op=read();
            if(op==1)
            {
                int x=read(),y=read(),c=read();
                updata(S[col[x][y]],x,y,-1);
                col[x][y]=c;
                updata(S[col[x][y]],x,y,1);
            }
            else
            {
                int x1=read(),x2=read(),y1=read(),y2=read(),c=read();
                printf("%d
    ",solve(S[c],x1,y1,x2,y2));
            }
        }
    }
  • 相关阅读:
    使用 Markdown Flow 画流程图
    两串锂电池的电池匹配
    笔记: CC2540 和 CC2541 的区别
    Elasticsearch 5.x 关于term query和match query的认识
    es 批量导入文件
    mac 下搭建Elasticsearch 5.4.3分布式集群
    Elastic Search 5.4.3 java api 入门
    solr java demo 基础入门
    创建索引并进行查询
    RabbitMq 之简单队列
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4798674.html
Copyright © 2011-2022 走看看