2次元imos (二次元いもす) ~yukicoder No.60 魔法少女~

Quiz

https://yukicoder.me/problems/no/60

AC code

https://yukicoder.me/submissions/443826

クラス化してみた

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];
  }
};

f:id:peroon:20200314043440p:plain