首页 > 其他分享 >Mobile phones-POJ1195

Mobile phones-POJ1195

时间:2023-02-06 18:31:34浏览次数:35  
标签:Mobile phones ++ d% POJ1195 int y1 input


Mobile phones


Time Limit: 5000MS

 

Memory Limit: 65536K

Total Submissions: 17445

 

Accepted: 8066


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. 


Mobile phones-POJ1195_mobile


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 3 2 0 0 2 2 1 1 1 2 1 1 2 -1 2 1 1 2 3 3


Sample Output


3

4


题意:



给出一个全0的矩阵,然后一些操作


0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次


1 X Y A:对于矩阵的X,Y坐标增加A


2 L B R T:询问(L,B)到(R,T)区间内值的总和


3:结束对这个矩阵的操作



代码:

# include <iostream>
# include <cstdio>
# include <cstring>
# define N 1024+10

using namespace std;

int c[N][N];
int n;

int bitlow(int x){
return x&(-x);
}

void modify(int x,int y,int d){

for(int i=x;i<=n;i+=bitlow(i)){
for(int j=y;j<=n;j+=bitlow(j)){
c[i][j]+=d;
}
}
}

int sum(int x,int y){

int ans = 0;
for(int i=x;i>0;i-=bitlow(i)){
for(int j=y;j>0;j-=bitlow(j)){
ans+=c[i][j];
}
}

return ans;
}

int main()
{

int m;
while(scanf("%d%d",&m,&n)!=EOF){

memset(c,0,sizeof(c));

int op;
while(scanf("%d",&op)){
int x,y,x1,y1,d;

if(op==1){
scanf("%d%d%d",&x,&y,&d);
++y,++x;
modify(x,y,d);
}else if(op==2){
scanf("%d%d%d%d",&x1,&y1,&x,&y);
++x,++y,++x1,++y1;
int ans = sum(x,y)-sum(x1-1,y)-sum(x,y1-1)+sum(x1-1,y1-1);
printf("%d\n",ans);
}else if(op==3){
//printf("\n");
break;
}
}
}
return 0;
}




标签:Mobile,phones,++,d%,POJ1195,int,y1,input
From: https://blog.51cto.com/u_15955675/6040222

相关文章

  • 开源即时通讯IM框架 MobileIMSDK v6.3 发布
    一、更新内容简介本次更新为次要版本更新,进行了若干优化(更新历史详见:码云ReleaseNodes)。可能是市面上唯一同时支持 UDP+TCP+WebSocket 三种协议的同类开源IM框架。二......
  • 安卓神器 -- PhoneSploit-Pro
    0x01工具介绍一体化客工具,可使用ADB和Metasploit-Framework远程利用Android设备获取Meterpreter会话。0x02安装与使用1、确保安装了所有必需的软件。打开终端并粘......
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:OCR组件
    本文简述如何在Smobiler中使用OCR组件进行文字识别。Step1.新建一个SmobilerForm窗体,并在窗体中加入OCR和Button,布局如下Button的点击事件代码:privatevoid......
  • 09-MobileNet 图像分类
       MobileNet的pytorch代码实现:1importtorch.nnasnn2fromcollectionsimportOrderedDict3importtorch4#fromtorchsummaryimportsummary......
  • 生成mobileconfig配置文件及签名
    配置描述文件是一个用于安装到设备的XML格式的文件,包含了相关的配置信息。用iPhone配置使用工具生成配置文件打开文件——新建配置文件,主要涉及使用到的配置如下:......
  • 20 个很棒的 jQuery Mobile 教程
    本文标题:20个很棒的jQueryMobile教程 ​​构建一个餐馆选择的Web应用​​​​​​HowtobuildajQueryMobileappforchoosingarestaurantbasedon......
  • jQuery Mobile主题使用与定制
    ​​http://www.adobe.com/cn/devnet/dreamweaver/articles/theme-control-jquery-mobile.html​​ 在上一篇文章​​jQueryMobile入门​​中,我提供了一种使用jQueryMobi......
  • 使用 jQuery Mobile 和 CSS3 实现响应式设计
    jQueryMobile框架是一个JavaScript库,您可以用它来轻松地创建了一个移动版本的网站,将现有的Web页面转换成触摸友好的网站和应用程序。jQueryMobile框架允许用户通过......
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:PDFView
    本文简述如何在Smobiler中使用PDFView。Step1.新建一个SmobilerForm窗体,再拖入PDfView,布局如下PDFView.ResourcrPath默认Document,指项目下\Resources\Document,若是pd......
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:PDFView
    本文简述如何在Smobiler中使用PDFView。Step1.新建一个SmobilerForm窗体,再拖入PDfView,布局如下PDFView.ResourcrPath默认Document,指项目下\Resources\Document,若是p......