| Question Description |
The length is N of the series A, and Q query, each time asked a period of weighted and S, the first number, the second number * *, and so on. S=σai* (i-l+1) (l<=i<=r) |
| Input |
First line, an integer n The second line, n number, represents a array, separated by a space. Third line, a positive integer q 4th to Q+3 line two positive integer L, R (L<=r), representing an interval, separated by a space. |
| Output |
| For each query, output results. Each result occupies one row. |
| Input example |
5 3 2 4) 3 5 3 1 3 2 5 3 4 |
| Output example |
19 39 10 |
| Other Notes |
| Data size: N, Q, ai<=100000 |
|
Ideas See albums
1#include <iostream>2 3 using namespacestd;4 Long Longa[101010],s[101010],w[101010];5 intMain ()6 {7 Long Longn,i;8scanf"%lld",&n);9 for(i=1; i<=n;i++) Ten { Onescanf"%lld",&a[i]); As[i]=s[i-1]+A[i]; -w[i]=w[i-1]+S[i]; - } the Long Longq,x,y,temp; -scanf"%lld",&q); - for(i=1; i<=q;i++) - { +scanf"%lld%lld",&x,&y); -Temp= (y-x+1) *s[y]-(w[y-1]-w[x-2]); +printf"%lld\n", temp); A } at return 0; -}interval weighting and
Interval weighting and