-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaticRangeSumQueries.java
More file actions
29 lines (27 loc) · 919 Bytes
/
StaticRangeSumQueries.java
File metadata and controls
29 lines (27 loc) · 919 Bytes
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
/*package whatever //do not write package name here */
import java.io.*;
class StaticRangeSumQueries{
public static void main (String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int q = Integer.parseInt(s[1]);
String s1[] = br.readLine().split(" ");
int a[] = new int[n];
for(int i = 0; i < n; i++) {
a[i] = Integer.parseInt(s1[i]);
}
long[] pre = new long[n+1];
for(int i = 0; i < n; i++) {
pre[i+1] = a[i] + pre[i];
}
StringBuilder sb = new StringBuilder();
while(q-- > 0) {
String s2[] = br.readLine().split(" ");
sb.append(pre[Integer.parseInt(s2[1])] - pre[Integer.parseInt(s2[0])-1] +" ");
sb.append("\n");
}
System.out.println(sb);
}
}