Interval weighting and

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.