백준 11659번 구간합 구하기4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <iostream> #include <queue> #include<stack> #include <cmath> #include<string> #include<vector> #include<algorithm> #include <cstring> //memset using namespace std; int n, m; int arr[100001]; int total[100001]; int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; total[0] = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; total[i] = total[i - 1] + arr[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; cout << total[b] - total[a - 1] << '\n'; } return 0; } | cs |
문제 출처:https://www.acmicpc.net/problem/11659
간단한 부분합배열을 만들어서 푸는 문제였습니다.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
이 코드를 추가 안하고 제출하니 자꾸 시간초과가 뜨네요.
위 코드는 cin cout입출력 함수의 시간을 줄이는 효과가 있습니다.
'알고리즘 > BAEKJOON' 카테고리의 다른 글
| 백준 14502번 연구소 (0) | 2019.09.19 |
|---|---|
| 백준 2805번 나무자르기 (0) | 2019.09.15 |
| 백준 11729번 하노이 탑 이동 순서 (0) | 2019.09.02 |
| 백준 14003번 가장 긴 증가하는 부분 수열 5 (0) | 2019.06.30 |
| 백준 2580번 스도쿠 (0) | 2019.06.30 |