K - Mobile phones

来源:互联网 发布:网络论坛 编辑:程序博客网 时间:2024/05/01 11:47

Time Limit: 5000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

Description

Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix. 

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 input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table. 


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

Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output.

Sample Input

0 41 1 2 32 0 0 2 2 1 1 1 21 1 2 -12 1 1 2 3 3

Sample Output

34
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std; #define MAXN  1300int c[MAXN][MAXN];int n;int lowbit(int x){return x&(-x);}void updata(int x,int y,int value){int i,j;for(i=x;i<=n;i+=lowbit(i))for(j=y;j<=n;j+=lowbit(j))c[i][j]+=value;}int query(int x,int y){int i,j;int sum=0;for(i=x;i>0;i-=lowbit(i))for(j=y;j>0;j-=lowbit(j)){sum+=c[i][j];}return sum;}int main(){int t;while(scanf("%d",&t)!=EOF){if(t==0){scanf("%d",&n);memset(c,0,sizeof(c));}else if(t==1){int x,y,val;scanf("%d%d%d",&x,&y,&val);updata(x+1,y+1,val);}else if(t==2){int ans;int x1,y2,x2,y1;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);ans=query(x1,y1)+query(x2+1,y2+1)-query(x1,y2+1)-query(x2+1,y1);printf("%d\n",ans);}else if(t==3)break;}return 0; }


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝卖家小儿说质量不合格怎么办 订单显示显示已签收没收到货怎么办 网上买过的东西查不到订单号怎么办 亚航的组合机票飞机延误怎么办 在微信上面对面红包被骗了钱怎么办 人欠我钱不给我怎么办 微信号被骗走然后骗了朋友钱怎么办 微信手机充值不到帐怎么办 中银香港密码器坏了怎么办 香港恒生银行的编码器丢了怎么办 淘宝拍下订单发货物流不显示怎么办 wish查到仿品审核变慢怎么办 淘宝卖家订单号错误无法修改怎么办 顺丰快递运单号微信扫描取消怎么办 买的王者荣耀号有守护平台怎么办 融e联登录密码错三次怎么办 金融e家u盾密码忘了怎么办 用工行网银转账后想取消交易怎么办 工行融e借没有密码器怎么办 工行融e借密码器丢了怎么办 工行融e联手机登录密码忘记怎么办 领导给员工抱怨工作太烦怎么办 员工抱怨忙的忙死闲的闲死怎么办 爱上骗我进传销的人该怎么办 尚赫辟谷期间吃了东西怎么办 肾结石掉在输尿管里面好痛怎么办 寄的快递快递单号找不到了怎么办 手机停机但是快递是这个号码怎么办 百世通快递卡在一个地方没动怎么办 电信无限流量20g用完了怎么办 至尊宝qq密保手机被更换怎么办 至尊宝账户密保手机被改怎么办 照片放到私密相册找不到了怎么办 出口报关报错境内货源地怎么办? 微信提现未到账交易记录删了怎么办 支付宝忘记密码就可以登陆怎么办 电脑上登陆QQ忘记密码了怎么办? 电脑被管理员限制登录微信了怎么办 快手绑定的手机号丢了登不上怎么办 快手绑定的手机号丢了登不了怎么办 苹果id有手机号不知道密码怎么办