~ ~ ~ Noodles ~ ~ ~
Exercises
Two-dimensional tree array of the board questions,,, learned so long the first time to write a two-dimensional tree array, ashamed AH.
Do not say how to write, look at the code bar.
It's the same as normal.
1#include <bits/stdc++.h>2 using namespacestd;3 #defineR Register int4 #defineAC 3025 #defineLowbit (x) (X & (×))6 intN, M, K;7 intA[ac][ac], C[ac][ac][ac];8 9InlineintRead ()Ten { One intx =0;Charc =GetChar (); A while(C >'9'|| C <'0') C =GetChar (); - while(c >='0'&& C <='9') x = x *Ten+ C-'0', C =GetChar (); - returnx; the } - -InlinevoidAddintXintYintWinth) - { + for(R i = x; i <= n; i + =lowbit (i)) - for(R j = y; j <= m; j + =Lowbit (j)) +C[I][J][W] + =h; A } at -InlineintSearchintXintYintW) - { - intAns =0; - if(! x | | |!y | | x > N | | y > m)return 0; - for(R i = x; i; I-=lowbit (i)) in for(R j = y; j; J-=Lowbit (j)) -Ans + =C[i][j][w]; to returnans; + } - the voidPre () * { $n = Read (), M =read ();Panax Notoginseng for(R i =1; I <= N; i++) - for(R j =1; J <= M; J + +) the { +A[I][J] =read (); AAdd (I, J, A[i][j],1);//To create a tree-like array the } + } - $ voidWork () $ { - intopt, x1, x2, X3, X4, X5, TMP; -K =read (); the for(R i =1; I <= K; i++) - {Wuyiopt =read (); the if(opt = =1) - { WuX1 = Read (), x2 = Read (), x3 =read (); - if(x3! =a[x1][x2]) About { $Add (x1, x2, a[x1][x2],-1);//eliminate the original value -Add (x1, x2, X3,1);//new Value Added -A[X1][X2] =X3; - } A } + Else the { -X1 = Read (), x3 = Read (), x2 = Read (), x4 = Read (), x5 =read (); $TMP = Search (x3, X4, X5)-Search (x3, X2-1, X5)-Search (x1-1, X4, X5) + Search (x1-1, X2-1, X5);//error,,,-1 AH theprintf"%d\n", TMP); the } the } the } - in intMain () the { the //freopen ("in.in", "R", stdin); About pre (); the Work (); the //fclose (stdin); the return 0; +}
[JSOI2009] Counting problem Two-dimensional tree array