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
- #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;
- }
优质内容筛选与推荐>>
1、linux命令行总结给自己看的版本2、git 初始化本地项目并推送到远程3、R小问题4、Oracle性能优化之普通用户使用dbms_xplan包需要有的权限5、SQL Server 如何添加删除外键、主键,以及更新自增属性
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
阅读
好看
已推荐到看一看
你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
取消
分享想法到看一看
确定
最多200字,当前共字
微信扫一扫
关注该公众号