Luogu P3932 on the island of 68th,

Source: Internet
Author: User

One day the goblins were playing games again. This game is like this.

The storage point of the Goblin storehouse can be seen on a single axis. Every storage point will have something, and there is a distance between them.

Every time they picked up a leprechaun and the rest of them found everything in the interval [l,r] storage point, and asked her after the inventory, what was the cost of transporting all the storage points in the range to another warehouse?

For example, the storage point I has x things, to be transported to the storage point JJ, the cost is x*dist (i,j)

Dist is the distance between warehouses.

Of course, because goblins don't count so much, so your answer needs to be 19260817 modulo

Input/output format

Input format:

The first row of two numbers represents n,m< Span class= "Strut bottom" >

Second row n-1 number, section Span class= "Katex" >i i number represents i< Span class= "Mord mathit" >i A storage point with i+< Span class= "Mord" > 1 storage points distance

The number of the third row n , indicating the number of items per storage point

three x l r numbers per line after M line

Represents the cost of the query to Transport All items of the interval [l,r] storage point to the storage point x

Output format:

For each query output a number for the answer

Analysis

About today's exam to find a problem practice practiced hand ...

I never thought it would be easier than a test, not even a change.

The difference between the test and the exam is that the distance between the neighboring points is much dist

Push the answers to each question

is ∑ (i=l~r) a[i] * ABS (D[I]-D[X])

To simplify is abs (∑ (I=L~R) (a[i]*d[x)-∑ (I=l~r) (A[i]*d[i]))

Then A[i]*d[i] can be preprocessed out of the interval and the positive and negative is clearly divided into X or so to solve

Anyway, it's relatively simple.

(If you maintain it with a modified tree array)

Code:

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <algorithm>5 #defineRep (i,a,n) for (int i = a;i <= n;i++)6 #definePer (i,n,a) for (int i = n;i >= a;i--)7 #defineINF 21474836478 using namespacestd;9typedefLong Longll;Ten ll Read () { Onell as=0, Fu =1; A     Charc =GetChar (); -      while(C <'0'|| C >'9') { -         if(c = ='-') Fu =-1; thec =GetChar (); -     } -      while(c >='0'&& C <='9') { -          as= as*Ten+ C-'0'; +c =GetChar (); -     } +     return  as*Fu; A } at Const intMoD =19260817; - Const intN =200006; - //Head - ll N,m; - ll A[n],d[n]; - ll Sa[n],mlt[n]; inLL Calc (intLintRintXBOOLop) { -     if(L > R)return 0; toll tmp1 = (Sa[r]-sa[l-1])% mod +MoD; +TMP1 = tmp1 * D[x]%MoD; -ll tmp2 = (Mlt[r]-mlt[l-1])% mod +MoD; the     if(OP) swap (TMP1,TMP2); *     return((TMP1-TMP2)%mod+mod)%MoD; $ }Panax Notoginseng  - intMain () { then =read (); +m =read (); ARep (I,2, N) { theD[i] = (d[i-1] + read ())%MoD; +     } -Rep (I,1, N) { $A[i] = read ()%MoD; $Sa[i] = (sa[i-1] + a[i])%MoD; -Mlt[i] = (mlt[i-1] + a[i] * d[i])%MoD; -     } theRep (I,1, M) { -         intx = Read (), L = Read (), r =read ();Wuyill ansl = Calc (l,min (X-1, R), X,0); thell ANSR = Calc (max (l,x+1), R,x,1); -printf"%lld\n", (ANSL+ANSR)%MoD); Wu     } -     return 0; About}

Okay, OK.

Luogu P3932 on the island of 68th,

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.