Description
Input
Output
Sample Input
Sample Output
1
2
HINT
At first, what do you want to do offline, in fact, not enough space, we directly open 100 two-dimensional tree array, and then the line
But if the C range is large, go offline and do some
1 type2Tree=Array[0.. -,0.. -] ofLongint;3 var4SArray[0.. -] ofTree;5A:Array[0.. -,0.. -] ofLongint;6 N,m,q:longint;7 8 procedureAddvarc:tree;x,y,w:longint);9 varTen I:longint; One begin A whileX<=n Do - begin -i:=y; the whileI<=m Do - begin - Inc (C[X,I],W); -i:=i+ (i and(-i)); + End; -x:=x+ (x and(-x)); + End; A End; at - functionSumvarc:tree;x,y:longint): Longint; - var - I:longint; - begin -sum:=0; in whileX>0 Do - begin toi:=y; + whileI>0 Do - begin the Inc (Sum,c[x,i]); *i:=i-(i and(-i)); $ End;Panax Notoginsengx:=x-(x and(-x)); - End; the End; + A proceduremain; the var + I,j,x1,y1,x2,y2,c:longint; - begin $ read (n,m); $ fori:=1 toN Do - forj:=1 toM Do - begin the read (a[i,j]); -Add (S[a[i,j]],i,j,1);Wuyi End; the read (q); - fori:=1 toQ Do Wu begin - Read (j); About ifj=1 Then $ begin - read (x1,y1,c); -Add (s[a[x1,y1]],x1,y1,-1); -a[x1,y1]:=C; AAdd (S[c],x1,y1,1); + End the Else - begin $ read (x1,x2,y1,y2,c); theWriteln (SUM (s[c],x2,y2) +sum (s[c],x1-1, y1-1)-sum (s[c],x1-1, y2)-sum (s[c],x2,y1-1)); the End; the End; the End; - in begin the main; the End.
View Code