JSOI2009 Count [tree-shaped array]

Source: Internet
Author: User

Tag: causes body ref www. Print its = = array getc

Bzoj

We can find that the n,m,c are very small, so just open 100 two-dimensional bit to maintain it. Each color corresponds to a bit.

Then query the time with a two-dimensional prefix and to engage in it.

Started in the Bzoj time is T, and later found that the bit is too large, resulting in a slow addressing.

#include <bits/stdc++.h>Const intmax_n=300+5;intN,m,q;inta[max_n][max_n],bit[101][max_n][max_n];inline intRead () {Register intx=0;Register CharCh=getchar (); while(!isdigit (CH)) Ch=getchar (); while(IsDigit (CH)) {x= (x<<1) + (x<<3) +ch-' 0 ';    Ch=getchar (); }returnx;}voidModifyintCintXintYintNUM) { for(intI=x;i<=n;i+=i&-i) for(intJ=Y;J&LT;=M;J+=J&AMP;-J) Bit[c][i][j]+=num;}intQueryintCintXintY) {intres=0; for(intI=x;i;i-=i&-i) for(intJ=Y;J;J-=J&AMP;-J) Res+=bit[c][i][j];returnRes;}intMain () {intOpt,x,y,xt,yt,c; N=read (), M=read (); for(intI=1; i<=n;++i) { for(intj=1; j<=m;++j) {a[i][j]=read (); Modify (A[i][j],i,j,1); }} q=read (); while(q--) {Opt=read ();if(opt==1) {X=read (), Y=read (), C=read ();if(A[X][Y]==C)Continue; Modify (A[x][y],x,y,-1);             A[x][y]=c; Modify (A[x][y],x,y,1); }Else{X=read (), Xt=read (), Y=read (), Yt=read (), C=read (); printf"%d\n", query (C,XT,YT)-query (c,xt,y-1)-query (c,x-1, YT) +query (c,x-1Y-1)); }    }return 0;}

JSOI2009 Count [tree-shaped array]

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.