public NumMatrix(int[][] m) {
            if (m == null || m.length == 0) return;

            tree = new int[m.length + 1][m[0].length + 1];
            matrix = m;
            for (int i = 0; i < m.length; ++i) {
                for (int j = 0; j < m[0].length; ++j) {
                    add(i, j, m[i][j]);
                }
            }
        }