Title Link: Hdu 4456 Crowd
Topic: Given n, then m operations
- 1 x y z: Add z at x, y position
- 2 x y z: Ask for a point value with X, y Manhattan distance less than Z.
Problem-solving ideas: Rotate the Matrix 45 degrees, then ask is equal to ask a rectangle, you can use the tolerance theorem to maintain a two-dimensional tree array, but the space open
, directly with the discretization, will be useful to the point processing out.
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intMAXN =4000005;Const intMAXM =80005;#Define lowbit (x) ((x) & ( ×))intN, M, W, E, h[maxn+5], FENW[MAXN +5];intO[MAXM], X[MAXM], Y[MAXM], Z[MAXM];inline intFind (intx) {returnLower_bound (H +1, H + E, x)-H;}voidHashpoint (intXintY) { for(inti = x; I <= W; i + = Lowbit (i)) { for(intj = y; J <= W; J + = Lowbit (j)) h[e++] = i * W + j; }}voidAddintXintYintD) { for(inti = x; I <= W; i + = Lowbit (i)) { for(intj = y; J <= W; J + = Lowbit (j)) {intpos = Find (i * W + j); Fenw[pos] + = D; } }}intSUM (intXintY) {intRET =0; for(inti = x; I I-= Lowbit (i)) { for(intj = y; J J-= Lowbit (j)) {intpos = Find (i * W + j);if(H[pos] = = i * W + j) ret + = Fenw[pos]; } }returnRET;}voidInit () {E =1; W =2Nscanf("%d", &m);memset(Fenw,0,sizeof(FENW)); for(inti =1; I <= M; i++) {scanf("%d%d%d%d", &o[i], &x[i], &y[i], &z[i]);intx = X[i]-y[i] + N;inty = X[i] + y[i];if(O[i] = =1) Hashpoint (x, y); } sort (H +1, H + E); E = unique (H +1, H + E)-H;}voidSolve () { for(inti =1; I <= M; i++) {intx = X[i]-y[i] + N;inty = X[i] + y[i];if(O[i] = =1) Add (x, Y, z[i]);Else{intA = max (1, X-z[i]);intb = Max (1, Y-z[i]);intc = min (W, x + z[i]);intd = min (W, y + z[i]);printf("%d\n", sum (c, D)-sum (c, B-1)-SUM (A-1, d) + sum (A-1, B-1)); } }}intMain () { while(scanf("%d", &n) = =1&& N) {init (); Solve (); }return 0;}
HDU 4456 Crowd (two-dimensional tree-like array)