All submissions for this problem are available.
Mr. Singh recently had a breakup with his girlfriend. Depressed, Mr. Singh decides to do what he loves - coding. But he is not able to solve the problem he got his hands on
which frustrates him even more. You are a friend of Mr. Singh and decide to help him solve the problem described below.
Given N non negative numbers, the task is to answer M queries.
Each query is as follows:
Given u,v you need to find the pairwise product sum (u and v are zero indexed)
auau + au+1au+1 + au+1au + au+2au
+2 + au+2au+1 + au+2au + ... + avav +
avav-1 + ... + avau
- The first line of the input contains an integer N denoting the number of elements.
- Next line contains N space separated integers
- Next line contains a single integer M denoting number of queries.
- Next M lines contain two integers u and v as described above.
- For each query,print the answer as described above in a new line.
- 1 ≤ N ≤ 100000
- 1 ≤ M ≤ 100000
- 0 ≤ u,v ≤ N-1
- 0 ≤ ai ≤ 100
Input: 5 2 0 1 3 3 2 0 2 1 2 Output: 7 1
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2|
Fetching successful submissions