zoukankan      html  css  js  c++  java
  • bzoj1452: [JSOI2009]Count

    二维BIT。。。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define rep(i,n) for(int i=1;i<=n;i++)
    #define clr(x,c) memset(x,c,sizeof(x))
    int read(){
    	int x=0;char c=getchar();
    	while(!isdigit(c)){
    		c=getchar();
    	}
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x;
    }
    const int nmax=305;
    const int maxn=105;
    #define lowbit(x) ((x)&-(x))
    int g[nmax][nmax],n,m,q;
    struct node{
    	int a[nmax][nmax];
    	node(){clr(a,0);}
    	void add(int x,int y,int v){
    		for(int i=x;i<=n;i+=lowbit(i))
    		  for(int j=y;j<=m;j+=lowbit(j)) a[i][j]+=v;
    	}
    	int sum(int x,int y){
    		int ans=0;
    		for(int i=x;i;i-=lowbit(i))
    		  for(int j=y;j;j-=lowbit(j)) ans+=a[i][j];
    		return ans;
    	}
    }; 
    node nodes[maxn];
    int main(){
    	n=read(),m=read();
    	rep(i,n) rep(j,m) g[i][j]=read(),nodes[g[i][j]].add(i,j,1);
    	q=read();
    	rep(i,q){
    		int temp=read();
    		if(temp==1){
    			int u=read(),v=read(),d=read();
    			nodes[g[u][v]].add(u,v,-1);
    			g[u][v]=d;nodes[d].add(u,v,1);
    		}else{
    			int u=read(),d=read(),v=read(),w=read(),tmp=read();
    			printf("%d
    ",nodes[tmp].sum(d,w)+nodes[tmp].sum(--u,--v)-nodes[tmp].sum(u,w)-nodes[tmp].sum(d,v));
    		}
    	}
    	return 0;
    }
    

      

    1452: [JSOI2009]Count

    Time Limit: 10 Sec  Memory Limit: 64 MB
    Submit: 1932  Solved: 1148
    [Submit][Status][Discuss]

    Description

    Input

    Output

    Sample Input



    Sample Output

    1
    2

    HINT

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    Spring中@Autowired注解与自动装配
    Nginx教程(一)-全面认知
    hadoop-mapreduce 详解
    python with hadoop
    大数据架构与技术选型
    hadoop-集群搭建
    虚拟机Vmware-网络配置
    linux 忘记密码
    高效编程之 小技巧归纳
    kafka 教程(四)-原理进阶
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5668394.html
Copyright © 2011-2022 走看看