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 ...
随机推荐
- XJTU Summer Holiday Test 1(Divisibility by Eight-8的倍数)
C - Divisibility by Eight Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- ios美颜 调研 GPUImage GPUImageBeautifyFilter BeautifyFaceDemo
最近需要给直播项目中添加美颜的功能,调研了很多SDK和开源代码(视决,涂图,七牛,金山云,videoCore等),综合成本/效果/对项目侵入性,最后决定使用一款基于GPUImage实现的 Beauti ...
- 利用GROUP_CONCAT函数把相同信息的合并到同一个字段中
SELECT a.*,GROUP_CONCAT(b.pri_name) FROM sh_role a LEFT JOIN sh_privilege b ON FIND_IN_SET(b.id,a.pr ...
- os如何处理键盘的所有按键,显示or不显示,显示是如何显示
[0]README 0.1) source code and text decription are from orange's implemention of a os , and for comp ...
- 【BZOJ3295】[Cqoi2011]动态逆序对 cdq分治
[BZOJ3295][Cqoi2011]动态逆序对 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依 ...
- EasyDSS高性能流媒体服务器前端重构(五)- webpack + vue-router 开发单页面前端实现按需加载 - 副本
为了让页面更快完成加载, 第一时间呈现给客户端, 也为了帮助客户端节省流量资源, 我们可以开启 vue-router 提供的按需加载功能, 让客户端打开页面时, 只自动加载必要的资源文件, 当客户端操 ...
- linux自动ftp上传与下载文件的简单脚本
#!/bin/sh cd /data/backup/55mysql DATE=`date +'%Y%m%d'`file="55_mysql_"$DATE"03*.rar& ...
- 九度OJ 1176:树查找 (完全二叉树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5209 解决:2193 题目描述: 有一棵树,输出某一深度的所有节点,有则输出这些节点,无则输出EMPTY.该树是完全二叉树. 输入: 输入 ...
- kafka source type
https://flume.apache.org/FlumeUserGuide.html # example.conf: A single-node Flume configuration # Nam ...
- PHP 关于路径的问题
<?php var_dump(basename(__FILE__)); //返回当前文件/文件夹的的文件名/目录名 var_dump(dirname(__FILE__)); //返回当前文件/文 ...