poj1195 Mobile phones
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 19786 | Accepted: 9133 |
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.
Input
The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3.
Table size: 1 * 1 <= S * S <= 1024 * 1024
Cell value V at any time: 0 <= V <= 32767
Update amount: -32768 <= A <= 32767
No of instructions in input: 3 <= U <= 60002
Maximum number of phones in the whole table: M= 2^30
Output
Sample Input
0 4
1 1 2 3
2 0 0 2 2
1 1 1 2
1 1 2 -1
2 1 1 2 3
3
Sample Output
3
4
Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,x,y,k,l,r,b,t,s;
int sz[][]; int lowbit(int x)
{
return x&-x;
}
void add(int x,int y,int k)
{
for(int i=x;i<=s;i+=lowbit(i))
for(int j=y;j<=s;j+=lowbit(j))
sz[i][j]+=k;
}
int sum(int x,int y)
{
int ans=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
ans+=sz[i][j];
return ans;
}
int main()
{
while(scanf("%d",&a)!=EOF)
{
if(a==){
scanf("%d",&s);
memset(sz,,sizeof());
}
if(a==)
{
scanf("%d%d%d",&x,&y,&k);
add(x+,y+,k);
}
if(a==)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
printf("%d\n",sum(r+,t+)-sum(l,t+)-sum(r+,b)+sum(l,b));
}
if(a==)break;
}
return ;
}
poj1195 Mobile phones的更多相关文章
- POJ1195 Mobile phones 【二维线段树】
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 6644 De ...
- POJ1195 Mobile phones 【二维树状数组】
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14288 Accepted: 6642 De ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- Mobile phones(poj1195)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18453 Accepted: 8542 De ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- C. Mobile phones
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- (Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 ppi 2GB/32GB 14.0Mp camera-in Mobile Phones from Electronics on Aliexpress.com
(Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 p ...
随机推荐
- spring-web中的StringHttpMessageConverter简介
spring的http请求内容转换,类似netty的handler转换.本文旨在通过分析StringHttpMessageConverter 来初步认识消息转换器HttpMessageConverte ...
- inflate, findViewById与setContentView的差别与联系
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
- Linux下Kafka单机安装配置方法
Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了普通消息系统的功能,但具有自己独特的设计.这个独特的设计是什么样的呢? 首先让我们看几个基本的消息系统术语: •Kafka将消息以topi ...
- Angular1.0路由的Hashbang和HTML5模式
原文答主jupiter http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashban ...
- mongo 介绍
[介绍]:MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能.MongoDB 旨在为WEB应用提供可扩展的高性能数据存 ...
- PHP错误调试
一:错误类型举例 1.语法错误:一般是语句最后缺少分号.缺少单引号或双引号.for循环或函数缺少花括号.缺少变量标示符$ 2.定义错误:一般是调用不存在的变量.调用不存在的函数或者类 3.逻辑错误:代 ...
- 【BZOJ4843】[Neerc2016]Expect to Wait 排序
[BZOJ4843][Neerc2016]Expect to Wait Description ls最近开了一家图书馆,大家听说是ls开的,纷纷过来借书,自然就会出现供不应求的情况, 并且借书的过程类 ...
- 【BZOJ3864】Hero meet devil DP套DP
[BZOJ3864]Hero meet devil Description There is an old country and the king fell in love with a devil ...
- django框架小技巧
带命名空间的URL名字 多应用中路由定义,采用命名空间,防止冲突 url(r'^polls/', include('polls.urls', namespace="polls")) ...
- getStorageSync const UID = this.$parent.UID wx.getStorageSync('UID')
getStorageSync 在程序运行中是在内存 还是去文件系统读取? const UID = this.$parent.UID wx.getStorageSync('UID') ...