We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
소스 코드
0,0 ~ i, j 까지의 누적합은 다음과 같다. s[i][j] = a[i][j] + s[i-1][j] + s[i][j-1] - s[i-1][j-1]
s[i][j] = a[i][j] + s[i-1][j] + s[i][j-1] - s[i-1][j-1]
이때 (x1, y1) ~ (x2, y2) 사이의 구간 합은 다음과 같다. s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1]
s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1]
입력과 동시에 값을 누적.
for(int i = 1; i<=N; ++i) { for(int j = 1; j<=N; ++j) { cin >> s[i][j]; s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1]; } } for(int m = 0; m<M; ++m) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; cout << s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1] << endl; }
The text was updated successfully, but these errors were encountered:
minsoo0715
No branches or pull requests
11660: 구간 합 구하기 5
소스 코드
아이디어
0,0 ~ i, j 까지의 누적합은 다음과 같다.
s[i][j] = a[i][j] + s[i-1][j] + s[i][j-1] - s[i-1][j-1]
이때 (x1, y1) ~ (x2, y2) 사이의 구간 합은 다음과 같다.
s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1]
구현
입력과 동시에 값을 누적.
The text was updated successfully, but these errors were encountered: