1452: [Jsoi2009]count-bzoj

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.