二维树状数组板子题。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 1000000000
#define maxn 40000
#define eps 1e-12
#define mod 1000000007
#define N 3005
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
return x*f;
}
int c[N][N],n;
int lowbit(int i)
{
return i&(-i);
}
int sum(int x,int y)
{
int ret=;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
ret+=c[i][j];
}
return ret;
}
void add(int x,int y,int d)
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
{
c[i][j]+=d;
}
}
int main()
{
int k,op,x,y,i,j;
while(~scanf("%d%d",&i,&n))
{
mem(c,);
while()
{
op=read();
if(op==) break;
if(op==) {
x=read();y=read();k=read();
add(x+,y+,k);
}
else{
int l,b,r,t;
l=read();b=read();r=read();t=read();
l++;b++;r++;t++;
printf("%d\n",sum(r,t)-sum(r,b-)-sum(l-,t)+sum(l-,b-));
}
}
}
return ;
}

POJ1195Mobile phones的更多相关文章

  1. POJ1195--Mobile phones(基础二维BIT)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  2. POJ1195Mobile phones (从二维树状数组到cdq分治)

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  3. poj1195Mobile phones(二维树状数组)

    http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  6. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  7. Deal with Android phones with pattern lock on

    Yesterday my colleague asked me for help...She has two android phones , one is hTC and the other is ...

  8. C. Mobile phones

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  9. 【POJ1195】【二维树状数组】Mobile phones

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

随机推荐

  1. 算法竞赛入门经典5.1 从c到c++

    这个章节主要是讲述了一些c++的特性,在这里面,对我用处最大的应该就是字符串吧.首先是getline,getchar,stringstream的使用了吧. 首先介绍这三个函数. 1. getline函 ...

  2. java设计模式3--观察者模式

    1.初步认识 观察者模式的定义: 在对象之间定义了一对多的依赖,这样一来,当一个对象改变状态,依赖它的对象会收到通知并自动更新. 大白话: 其实就是发布订阅模式,发布者发布信息,订阅者获取信息,订阅了 ...

  3. 初识redis-cluster

    安装redis [root@localhost ~]# cd /datas/soft/ [root@localhost soft]# ll redis-.tar.gz // 已经下载的最新版 -rwx ...

  4. lnmp启用pathinfo并隐藏index.php

    编辑如下区段: location ~ [^/]\.php(/|$) { # comment try_files $uri =404; to enable pathinfo try_files $uri ...

  5. python中函数返回多个值

    用ipython运行情况如下: # 新建一个函数 In [1]: def nums(): ...: a = 11 ...: b = 22 ...: c = 33 ...: return [a,b,c] ...

  6. python3.7 os模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 os模块 #os模块是与操作系统交互的一个接口 # os.get ...

  7. oracle 事务 锁机制

    原文地址:http://www.cnblogs.com/quanweiru/archive/2013/05/24/3097367.html 本课内容属于Oracle高级课程范畴,内容略微偏向理论性,但 ...

  8. 适合学习C语言开源项目——嵌入式脚本语言 Berry

    嵌入式脚本语言 Berry github网址 :https://github.com/Skiars/berry Berry 是一款面向小型嵌入式系统的脚本语言,目前发布了 0.1.0 版本.相比于其他 ...

  9. 线性回归、逻辑回归(LR)

    线性回归 回归是一种极易理解的模型,就相当于y=f(x),表明自变量 x 和因变量 y 的关系.最常见问题有如 医生治病时的望.闻.问.切之后判定病人是否生了什么病,其中的望闻问切就是获得自变量x,即 ...

  10. leetcode 【 Add Two Numbers 】 python 实现

    题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...