(简单) 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> # ...
随机推荐
- 详细的SQL中datediff用法
DATEDIFF 函数 [日期和时间] 功能返回两个日期之间的间隔. 语法DATEDIFF ( date-part, date-expression-1, date-expression-2 ) da ...
- js冒泡事件小解
何为冒泡事件?简单来说事件就像一个水里的泡泡,先触发当前对象再触发其父元素,然后是父元素的父元素... eg: <div class="out" onclick= " ...
- 【floyd 多源最短路】 poj 1125
#include <stdio.h> #include <iostream> #include <memory.h> using namespace std; ][ ...
- OpenGL———混合的基本知识
混合是一种常用的技巧,通常可以用来实现半透明.但其实它也是十分灵活的,你可以通过不同的设置得到不同的混合结果,产生一些有趣或者奇怪的图象.混合是什么呢?混合就是把两种颜色混在一起.具体一点,就是把某一 ...
- [转]java构造方法的访问修饰符
http://my.oschina.net/u/1464678/blog/210359 1. 类(class) 可见性修饰符: public—在所有类中可见,在其他包中可以用import导 ...
- 2016湖南省赛--A题--2016
2016 [TOC] Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input ...
- SAX,DOM,JAXP,JDOM,DOM4J比较
dom,sax,jdom,dom4j的技术特点: 1: DOMDOM 是用与平台和语言无关的方式表示 XML 文档的官方 W3C 标准.DOM 是以层次结构组织的节点或信息片断的集合.这个层次结构允许 ...
- 学习笔记——单例模式Singleton
单例模式,很容易理解,就它一个. 比如网络请求服务类WebReq.它自己生成请求线程,并管理请求数据的返回,所以我们使用它进行网络请求时,不用每次都new一个,只需要使用一个实例就行了.WebReq实 ...
- mysql数据库主从备份
近期实验室总是不给通知的就停电,导致我们在不停的恢复服务.在某一个断电的过程中,发现我们的项目管理工具redmine的硬盘挂掉了..因为是部署在虚拟机上的,也没做冗余,数据就丢了..于是反思,我们的m ...
- dage手法之 头部和banner ad tpl_header
<div class="top2"> <?php if ($current_page_base == 'index' || $current_page_base ...