[bzoj1452] [JSOI2009] Count

Source: Internet
Author: User

From Falldream's blog, without permission, please do not reprint, thank you.

There is a n*m matrix with a weighted value for each point.

Need to support two operations: 1) Change the weight of a point 2) query the number of values in a rectangle with a weight of C

n,m<=300 q<=200000 Weight Value <=100

A little bit of weight, right? Let's open a two-dimensional tree array for each weight.

#include <cstdio>#include<iostream>#defineMN 300using namespaceStd;inlineintRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}ints[ the][mn+5][mn+5],c[mn+5][mn+5],n,m;voidRenewintCintXintYintAD) {     for(inti=x;i<=n;i+=i& (-i)) for(intj=y;j<=m;j+=j& (-j)) S[c][i][j]+=AD;}intQueryintCintXinty) {    intsum=0;  for(inti=x;i;i-=i& (-i)) for(intj=y;j;j-=j& (-j)) Sum+=S[c][i][j]; returnsum;}intMain () {n=read (); m=read ();  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) C[i][j]=read (), Renew (C[i][j],i,j,1);  for(intQ=read (); q--;) {        intop=read (); if(op==1)        {            intX=read (), Y=read (), col=read (); Renew (C[x][y],x,y,-1); Renew (Col,x,y,1); C[x][y]=Col; }        Else        {            intX=read (), X2=read (), Y=read (), Y2=read (), c=read (); printf ("%d\n", query (c,x2,y2) +query (c,x-1, Y1)-query (c,x-1, y2)-query (c,x2,y-1)); }    }    return 0;}

[bzoj1452] [JSOI2009] Count

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.