比赛 |
20110728 |
评测结果 |
AAAEEEEEEE |
题目名称 |
蝗灾 |
最终得分 |
30 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-28 08:35:36 |
显示代码纯文本
program locust;
const
maxn=5000;
var
c:array[0..maxn,0..maxn] of longint;
n,m,i,j,i1,j1,w,t,r:longint;
procedure modify(i,j,w:longint);
var
j0:longint;
begin
while i<=n do
begin
j0:=j;
while j0<=m do
begin
inc(c[i,j0],w);
j0:=j0+(j0 and (-j0));
end;
i:=i+(i and (-i));
end;
end;
function getsum(i,j:longint):longint;
var
j0,sum:longint;
begin
sum:=0;
while i>0 do
begin
j0:=j;
while j0>0 do
begin
inc(sum,c[i,j0]);
j0:=j0-(j0 and (-j0));
end;
i:=i-(i and (-i));
end;
exit(sum);
end;
begin
assign(input,'locust.in');
reset(input);
assign(output,'locust.out');
rewrite(output);
read(n);
read(m);
for t:=1 to m do
begin
read(r);
if r=1 then
begin
read(i,j,w);
modify(i,j,w);
end
else
begin
read(i,j,i1,j1);
writeln(getsum(i1,j1)-getsum(i-1,j1)-getsum(i1,j-1)+getsum(i-1,j-1));
end;
end;
close(input);
close(output);
end.