记录
10:07 2024-3-4
1.前缀和
1.一维前缀和
数组A[x] (下标从1开始)
前缀和S[0] = 0 S[i] = S[i - 1] + A[i]
2.二维前缀和
数组A[x][y] (下标从1开始)
前缀和S[i][j]表示以(i,j)为右下角的矩形中所有元素的和
S[i][0] = S[0][j] = 0
S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + A[i][j]
记录
10:07 2024-3-4
数组A[x] (下标从1开始)
前缀和S[0] = 0 S[i] = S[i - 1] + A[i]
数组A[x][y] (下标从1开始)
前缀和S[i][j]表示以(i,j)为右下角的矩形中所有元素的和
S[i][0] = S[0][j] = 0
S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + A[i][j]