BZOJ 1062
program candy bzoj1062; const maxc=1000100; maxm=4010; maxn=2010; var n,len,m,i,p,t,l,r,c,d,q:longint; s:array[0..1,0..maxn,0..maxm] of longint; x,y:array[0..maxc] of longint; procedure add(p,x,y,v:longint); var i:longint; begin inc(x); inc(y); while x<maxn do begin i:=y; while i<maxm do begin inc(s[p,x,i],v); inc(i,i and -i); end; inc(x,x and -x); end; end; function sum(p,x,y:longint):longint; var i:longint; begin if (x<0)or(y<0) then exit(0); inc(x); inc(y); sum:=0; if x>n then x:=n+1; if y>m then y:=m+1; while x>0 do begin i:=y; while i>0 do begin inc(sum,s[p,x,i]); dec(i,i and -i); end; dec(x,x and -x); end; end; procedure update(t,c,l,r,d:longint); inline; begin x[c]:=(t-d*l+n) mod n; y[c]:=r-l; add(0,x[c],y[c]+x[c],1); add(1,x[c],y[c]-x[c]+n,1); end; procedure change(c:longint); inline; begin add(0,x[c],y[c]+x[c],-1); add(1,x[c],y[c]-x[c]+n,-1); end; function area(p,x1,y1,x2,y2:longint):longint; inline; begin area:=sum(p,x2,y2)+sum(p,x1-1,y1-1)-sum(p,x1-1,y2)-sum(p,x2,y1-1); end; function ask(t,l,r:longint):longint; inline; var d:longint; begin d:=longint(r=len); ask:=area(0,t,l+t,t+r,m)+area(0,0,l+t-n,t+r-n-d,m)+area(1,t-r+n+d,l-t,n,m)+area(1,t-r,l-t+n,t-1,m); end; begin read(q,len); n:=len<<1; m:=len<<2; for i:=1 to q do begin read(p); case p of 1:begin read(t,c,l,r,d); update(t,c,l,r,d); end; 2:begin read(t,l,r); writeln(ask(t mod n,l,r)); end; 3:begin read(t,c); change(c); end; end; end; end.
让别人无路可走