(简单) POJ 1195 Mobile phones,二维树状数组。
Description
Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area.
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 14时44分13秒
// File Name : 1195.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int C[MaxN][MaxN];
int N; inline int lowbit(int x)
{
return x&(-x);
} void add(int x,int y,int d)
{
int t; while(x<=N)
{
t=y; while(t<=N)
{
C[x][t]+=d;
t+=lowbit(t);
} x+=lowbit(x);
}
} int query(int x,int y)
{
int ret=;
int t; while(x>)
{
t=y; while(t>)
{
ret+=C[x][t];
t-=lowbit(t);
} x-=lowbit(x);
} return ret;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int a,b,c,d,e; while()
{
scanf("%d",&a); if(a==)
{
scanf("%d %d %d",&b,&c,&d);
add(b+,c+,d);
}
else if(a==)
{
scanf("%d %d %d %d",&b,&c,&d,&e);
printf("%d\n",query(d+,e+)-query(d+,c)-query(b,e+)+query(b,c));
}
else if(a==)
{
scanf("%d",&N);
memset(C,,sizeof(C));
}
else
break;
} return ;
}
(简单) POJ 1195 Mobile phones,二维树状数组。的更多相关文章
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- 【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
- POJ 2155 Matrix 【二维树状数组】(二维单点查询经典题)
<题目链接> 题目大意: 给出一个初始值全为0的矩阵,对其进行两个操作. 1.给出一个子矩阵的左上角和右上角坐标,这两个坐标所代表的矩阵内0变成1,1变成0. 2.查询某个坐标的点的值. ...
- POJ 2155 Matrix (二维树状数组)题解
思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- POJ 2155 Matrix(二维树状数组)
与以往不同的是,这个树状数组是二维的,仅此而已 #include <iostream> #include <cstdio> #include <cstring> # ...
随机推荐
- Hibernate 系列教程5-双向多对一
主要讲解inverse和cascade的用法 cascade定义的是关系两端对象到对象的级联关系: 而inverse定义的是关系和对象的级联关系(管理外键的值). inverse 属性默认是false ...
- linux command----vi
vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器.Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved),与vi编辑器完全兼容,而且实现了很多增强功能. ...
- 在win7 64bit系统安装QC软件
当本机系统不再QC软件支持的系统上,可以在setup右键选择兼容性选择能支持安装的系统, 在JBOSS页面,选择该服务器,用户名输入本机的用户名和密码,如果没有配置域输入计算机名. 如果没有装IIS, ...
- ARC属性中还能使用assign,copy,retain这些关键字吗
http://blog.sina.com.cn/s/blog_6531b9b80101c6cr.html 很早以前比较弱,网上不知道哪里看了篇博文,留下了ARC属性中不能使用retain关键 ...
- <link rel="stylesheet" href="3.css"/> 链接方式
<link rel="stylesheet" href="3.css"/> <!doctype html> <html> & ...
- css05 字体以及行间距
<head><meta charset="utf-8"><title>无标题文档</title><style>#box{ ...
- hadoop工作流引擎之azkaban
Azkaban是twitter出的一个任务调度系统,操作比Oozie要简单很多而且非常直观,提供的功能比较简单.Azkaban以Flow为执行单元进行定时调度,Flow就是预定义好的由一个或多个可存在 ...
- 河南多校大一训练赛 C 青蛙的约会
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/C 密码:acm Description 两只青蛙在网上相识了,它们聊得很开心,于是 ...
- mysql数据库主从备份
近期实验室总是不给通知的就停电,导致我们在不停的恢复服务.在某一个断电的过程中,发现我们的项目管理工具redmine的硬盘挂掉了..因为是部署在虚拟机上的,也没做冗余,数据就丢了..于是反思,我们的m ...
- HTML5来了:5个好用的混合式App开发工具
在残酷的移动互联网竞争环境下, HTML5技术一直受到各方关注,“HTML5颠覆原生 App”的争论也从未停止过,不管怎样HTML5生态的构建方兴未艾.不过对于移动开发者来说更关心的问题是如何低成本. ...