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