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 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
  1. #include"stdio.h"
  2. #include"string.h"
  3. long long int c[1050][1050];
  4. int s;
  5. int lowbit(int x)
  6. {
  7. return x&(-x);
  8. }
  9. void updata(int x,int y,int d)
  10. {
  11. while(x<=s)
  12. {
  13. int y1=y;
  14. while(y1<=s)
  15. {
  16. c[x][y1]+=d;
  17. y1+=lowbit(y1);
  18. }
  19. x+=lowbit(x);
  20. }
  21. }
  22. long long int getsum(int x,int y)
  23. {
  24. long long int res=0;
  25. while(x>0)
  26. {
  27. int y1=y;
  28. while(y1>0)
  29. {
  30. res+=c[x][y1];
  31. y1-=lowbit(y1);
  32. }
  33. x-=lowbit(x);
  34. }
  35. return res;
  36. }
  37. int main()
  38. {
  39. int x1,y1,x2,y2,flag,i;
  40. long long int d;
  41. while(scanf("%d",&flag)!=EOF)
  42. {
  43. if(flag==3)
  44. break;
  45. else if(flag==0)
  46. {
  47. scanf("%d",&s);
  48. s++;
  49. memset(c,0,sizeof(c));
  50. }
  51. else if(flag==1)
  52. {
  53. scanf("%d%d%lld",&x1,&y1,&d);
  54. x1++;
  55. y1++;
  56. updata(x1,y1,d);
  57. }
  58. else if(flag==2)
  59. {
  60. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  61. x1++;
  62. y1++;
  63. x2++;
  64. y2++;
  65. long long int sum=0;
  66. sum=getsum(x2,y2)-getsum(x1-1,y2)-getsum(x2,y1-1)+getsum(x1-1,y1-1);
  67. printf("%lld\n",sum);
  68. }
  69. }
  70. return 0;
  71. }

C. Mobile phones的更多相关文章

  1. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  2. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  3. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  4. 【POJ1195】【二维树状数组】Mobile phones

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  5. (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 ...

  6. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  7. Mobile phones POJ - 1195 二维树状数组求和

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  8. POJ1195 Mobile phones 【二维线段树】

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14291   Accepted: 6644 De ...

  9. poj1195 Mobile phones

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 19786   Accepted: 9133 De ...

随机推荐

  1. [翻译]创建ASP.NET WebApi RESTful 服务(10)

    通过URI实现版本管理 另一种实现版本管理的方式就是通过URI来进行处理,类似于http://localhost:{your_port}/api/v1/students/.这种方式的好处是使用者可以清 ...

  2. 安装glibc2.7

    参考链接http://fhqdddddd.blog.163.com/blog/static/18699154201401722649441/ /lib/libc.so.6: version `glib ...

  3. I/O小总结

    //判断不存在就创建目录 ,然后拷贝文件 DirectoryInfo di = null; if (!Directory.Exists(n.Attribute("value").V ...

  4. HIT 2275 Number sequence

    点击打开HIT 2275 思路: 树状数组 分析: 1 题目要求的是总共的搭配方式,满足Ai < Aj > Ak.并且i j k不同 2 我们开两个树状数组,第一个在输入的时候就去更新.然 ...

  5. conn,stmt,rset 的关闭(规范)

    Connection conn = null; Statement stmt = null; ResultSet rset = null; try { conn = dataSource.getCon ...

  6. 解决Android singleTask模式下PendingIntent不能给onNewIntent传值的Bug

    http://phenix.blogbus.com/logs/220656659.html 博主简直碉堡了, 我用PendingIntent给singleTask的顶层Activity传值一直收不到, ...

  7. ssh+dwr 的使用源码案例

    加入dwr.jar包 ======jsp=============== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona ...

  8. C# 浅拷贝与深拷贝

    浅拷贝:给对象拷贝一份新的对象引用地址:(只是给一个对象多起了个名字,所以,当改变拷贝的某个属性的时候,原对象的对应属性亦会改变).浅拷贝的定义—— 只对值类型(或string)类型分配新的内存地址: ...

  9. 使用php代码如何筛选出ie6及以下的浏览器。

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-04-09) <?php //ie6及以下的浏览器不加载js_menu文件. if (strpos($_SERVER[' ...

  10. 使用java实现持续移动的小球

    原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5559829.html 仅为自己学习作品,使用java的JFrame框架实现持续移动的小球. ...