Drunk Queries
Time Limit: 2 sec
Memory Limit: 256 MB
Attempts: 266
Accuracy: 3.38%
Author: Ketan Gupta
Nitin has been given an array A of N integers and now, he has to answer Q questions.
A question has two integers L and R and the answer to a particular query is:
F(L, R) = A[L] - A[L+1] + A[L+2] - A[L+3] + ... + A[R]*(-1)(R-L)
But since Nitin is not sober, you have to answer all the questions for him.
Input Format:
The first line of input contains the value N. N denotes the size of array.
The next line contains N spaced integers. These N integers denote the array.
The next line contains the value Q which denotes the number of queries.
Then, Q lines follow each containing two integers L and R.
Output Format:
You have to output Q integers, each denoting the answer to the corresponding query.
Constraints:
1 <= N <= 10^5
1 <= Q <= 10^5
1 <= L <= R <= N
1 <= A[i] <= 10^9
Sample Input:
5
4 5 6 1 2
3
1 1
2 4
3 5
Sample Output:
4
0
7
ID
SUBMITTED AT
STATUS
LANGUAGE
TIME
MEMORY USED
USER
TIME
STATUS
LANGUAGE
TIME
MEMORY USED
1 year ago
cpp14
0.00 sec
0 KB
1 year ago
cpp
0.00 sec
0 KB
1 year ago
cpp
0.00 sec
0 KB
1 year ago
cpp
0.00 sec
0 KB
1 year ago
cpp
0.00 sec
0 KB
2 years ago
java
0.00 sec
0 KB
2 years ago
java
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
2 years ago
cpp14
0.00 sec
0 KB
2 years ago
cpp14
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
2 years ago
cpp14
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
2 years ago
cpp
0.00 sec
0 KB
3 years ago
cpp
0.00 sec
0 KB
3 years ago
cpp14
0.00 sec
0 KB
3 years ago
cpp
0.00 sec
0 KB
3 years ago
cpp14
0.00 sec
0 KB
3 years ago
java
0.00 sec
0 KB
3 years ago
java
0.00 sec
0 KB
3 years ago
cpp
0.00 sec
0 KB
3 years ago
cpp
0.00 sec
0 KB
3 years ago
cpp14
0.00 sec
0 KB
3 years ago
cpp14
0.00 sec
0 KB
4 years ago
cpp
0.00 sec
0 KB
4 years ago
cpp
0.00 sec
0 KB
4 years ago
cpp
0.00 sec
0 KB
4 years ago
cpp
0.00 sec
0 KB
4 years ago
cpp
0.31 sec
1172 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.26 sec
3600 KB
4 years ago
cpp14
0.26 sec
1952 KB
4 years ago
cpp
0.27 sec
1952 KB
4 years ago
cpp14
0.07 sec
64 KB
4 years ago
cpp
2.00 sec
384 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.26 sec
1952 KB
4 years ago
cpp
2.00 sec
388 KB
4 years ago
java
0.12 sec
428 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
java
0.12 sec
428 KB
4 years ago
java
0.12 sec
428 KB
4 years ago
java
0.17 sec
428 KB
4 years ago
java
0.00 sec
0 KB
4 years ago
java
0.00 sec
0 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp14
0.26 sec
968 KB
4 years ago
cpp14
0.34 sec
1672 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp14
2.00 sec
388 KB
4 years ago
cpp14
2.00 sec
388 KB
4 years ago
cpp14
0.07 sec
64 KB
4 years ago
cpp14
2.00 sec
388 KB
4 years ago
cpp14
0.07 sec
64 KB
4 years ago
cpp14
0.07 sec
64 KB
4 years ago
cpp14
0.26 sec
1676 KB
4 years ago
java
2.17 sec
428 KB
4 years ago
java
2.16 sec
428 KB
4 years ago
java
0.14 sec
428 KB
4 years ago
java
0.15 sec
428 KB
4 years ago
java
2.06 sec
428 KB
4 years ago
java
2.13 sec
428 KB
4 years ago
java
2.17 sec
428 KB
4 years ago
java
2.14 sec
428 KB
4 years ago
java
0.15 sec
428 KB
4 years ago
java
2.08 sec
428 KB
4 years ago
cpp14
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB
4 years ago
cpp
0.07 sec
64 KB