C. Mobile phones
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
- #include"stdio.h"
- #include"string.h"
- long long int c[1050][1050];
- int s;
- int lowbit(int x)
- {
- return x&(-x);
- }
- void updata(int x,int y,int d)
- {
- while(x<=s)
- {
- int y1=y;
- while(y1<=s)
- {
- c[x][y1]+=d;
- y1+=lowbit(y1);
- }
- x+=lowbit(x);
- }
- }
- long long int getsum(int x,int y)
- {
- long long int res=0;
- while(x>0)
- {
- int y1=y;
- while(y1>0)
- {
- res+=c[x][y1];
- y1-=lowbit(y1);
- }
- x-=lowbit(x);
- }
- return res;
- }
- int main()
- {
- int x1,y1,x2,y2,flag,i;
- long long int d;
- while(scanf("%d",&flag)!=EOF)
- {
- if(flag==3)
- break;
- else if(flag==0)
- {
- scanf("%d",&s);
- s++;
- memset(c,0,sizeof(c));
- }
- else if(flag==1)
- {
- scanf("%d%d%lld",&x1,&y1,&d);
- x1++;
- y1++;
- updata(x1,y1,d);
- }
- else if(flag==2)
- {
- scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
- x1++;
- y1++;
- x2++;
- y2++;
- long long int sum=0;
- sum=getsum(x2,y2)-getsum(x1-1,y2)-getsum(x2,y1-1)+getsum(x1-1,y1-1);
- printf("%lld\n",sum);
- }
- }
- return 0;
- }
C. Mobile phones的更多相关文章
- 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 ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- (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 ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- 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: 19786 Accepted: 9133 De ...
随机推荐
- [翻译]创建ASP.NET WebApi RESTful 服务(10)
通过URI实现版本管理 另一种实现版本管理的方式就是通过URI来进行处理,类似于http://localhost:{your_port}/api/v1/students/.这种方式的好处是使用者可以清 ...
- 安装glibc2.7
参考链接http://fhqdddddd.blog.163.com/blog/static/18699154201401722649441/ /lib/libc.so.6: version `glib ...
- I/O小总结
//判断不存在就创建目录 ,然后拷贝文件 DirectoryInfo di = null; if (!Directory.Exists(n.Attribute("value").V ...
- HIT 2275 Number sequence
点击打开HIT 2275 思路: 树状数组 分析: 1 题目要求的是总共的搭配方式,满足Ai < Aj > Ak.并且i j k不同 2 我们开两个树状数组,第一个在输入的时候就去更新.然 ...
- conn,stmt,rset 的关闭(规范)
Connection conn = null; Statement stmt = null; ResultSet rset = null; try { conn = dataSource.getCon ...
- 解决Android singleTask模式下PendingIntent不能给onNewIntent传值的Bug
http://phenix.blogbus.com/logs/220656659.html 博主简直碉堡了, 我用PendingIntent给singleTask的顶层Activity传值一直收不到, ...
- ssh+dwr 的使用源码案例
加入dwr.jar包 ======jsp=============== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona ...
- C# 浅拷贝与深拷贝
浅拷贝:给对象拷贝一份新的对象引用地址:(只是给一个对象多起了个名字,所以,当改变拷贝的某个属性的时候,原对象的对应属性亦会改变).浅拷贝的定义—— 只对值类型(或string)类型分配新的内存地址: ...
- 使用php代码如何筛选出ie6及以下的浏览器。
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-04-09) <?php //ie6及以下的浏览器不加载js_menu文件. if (strpos($_SERVER[' ...
- 使用java实现持续移动的小球
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5559829.html 仅为自己学习作品,使用java的JFrame框架实现持续移动的小球. ...