File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
백준/Silver/11659. 구간 합 구하기 4 Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # [ Silver III] 구간 합 구하기 4 - 11659
2
+
3
+ [ 문제 링크] ( https://www.acmicpc.net/problem/11659 )
4
+
5
+ ### 성능 요약
6
+
7
+ 메모리: 62512 KB, 시간: 1712 ms
8
+
9
+ ### 분류
10
+
11
+ 누적 합
12
+
13
+ ### 제출 일자
14
+
15
+ 2024년 3월 28일 21:35:30
16
+
17
+ ### 문제 설명
18
+
19
+ <p >수 N개가 주어졌을 때, i번째 수부터 j번째 수까지 합을 구하는 프로그램을 작성하시오.</p >
20
+
21
+ ### 입력
22
+
23
+ <p >첫째 줄에 수의 개수 N과 합을 구해야 하는 횟수 M이 주어진다. 둘째 줄에는 N개의 수가 주어진다. 수는 1,000보다 작거나 같은 자연수이다. 셋째 줄부터 M개의 줄에는 합을 구해야 하는 구간 i와 j가 주어진다.</p >
24
+
25
+ ### 출력
26
+
27
+ <p >총 M개의 줄에 입력으로 주어진 i번째 수부터 j번째 수까지 합을 출력한다.</p >
28
+
Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+ import java .util .stream .*;
4
+ public class Main {
5
+ public static void main (String [] args ) throws IOException {
6
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7
+ int c = Integer .parseInt (br .readLine ().split (" " )[1 ]);
8
+ int [] arr = Arrays .stream (br .readLine ().split (" " )).mapToInt (Integer ::parseInt ).toArray ();
9
+ Arrays .parallelPrefix (arr , (a ,b )->a +b );
10
+ for (int i =0 ; i <c ; i ++) {
11
+ StringTokenizer tk = new StringTokenizer (br .readLine ());
12
+ int x = Integer .parseInt (tk .nextToken ()) -1 ;
13
+ int y = Integer .parseInt (tk .nextToken ()) -1 ;
14
+ System .out .println (arr [y ] - (x == 0 ? 0 : arr [x -1 ]));
15
+ }
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments