Skip to content
New issue

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

11659: 구간 합 구하기 4 #35

Open
minsoo0715 opened this issue Nov 20, 2023 · 0 comments
Open

11659: 구간 합 구하기 4 #35

minsoo0715 opened this issue Nov 20, 2023 · 0 comments
Assignees
Labels
#누적합 누적합 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들

Comments

@minsoo0715
Copy link
Owner

minsoo0715 commented Nov 20, 2023

11659: 구간 합 구하기 4

소스 코드

아이디어

누적합 배열에서 특정 구간 [i, j]의 합은 다음과 같다.
$$S_{j} - S_{i-1} ~~~(S_{0} = 0)$$

구현

// 누적합 배열 생성
for(int i = 1; i<=N; ++i) {
    cin >> v[i];
    if(i > 1) {
        v[i] += v[i-1];
    }
}

// 구간 합 출력
for(int i = 1; i<=M; ++i) {
    int m, n;
    cin >> m >> n;
    cout << v[n] - v[m-1] << endl;
}
@minsoo0715 minsoo0715 added the #누적합 누적합 문제 label Nov 20, 2023
@minsoo0715 minsoo0715 added @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들 labels Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#누적합 누적합 문제 @백준 백준(https://www.acmicpc.net) 문제 C/C++ c/c++로 해결한 문제들
Projects
None yet
Development

No branches or pull requests

1 participant