クラス化した
struct Imos2D{ VV A; ll H,W; Imos2D(ll h, ll w){ H = h; W = w; A.resize(H, VI(W)); } // [(y0,x0), (y1,x1)] void add(ll y0, ll x0, ll y1, ll x1, ll v){ A[y0][x0] += v; A[y1+1][x1+1] += v; A[y0][x1+1] -= v; A[y1+1][x0] -= v; } void calc(){ // horizontal imos rep(y,H){ rep(x,W-1){ A[y][x+1] += A[y][x]; } } // vertical imos rep(x, W){ rep(y, H-1){ A[y+1][x] += A[y][x]; } } } ll val(ll y, ll x){ return A[y][x]; } };
類題 verify
- 典型90 028-Cluttered Paper(★4)