luogu#P7922. [Kubic] Pyramid

[Kubic] Pyramid

Background

It is easy to see that the setter of Problem F is not lxl.

Problem Description

You are given a sequence pp with initial length nn.

Let the current length of pp be LL. There are two kinds of operations:

  • Operation A first constructs a sequence pp' of length L1L-1 such that pi=min{pi,pi+1},i[1,L)p_i'=\min\{p_i,p_{i+1}\},i\in [1,L). Then replace pp with pp'.

  • Operation B first constructs a sequence pp' of length L1L-1 such that pi=max{pi,pi+1},i[1,L)p_i'=\max\{p_i,p_{i+1}\},i\in [1,L). Then replace pp with pp'.

You are also given a sequence aa of length mm, meaning there are mm groups of operations. In the ii-th group, perform aia_i times operation A first, and then perform aia_i times operation B. It is guaranteed that 2ai=n12\sum a_i=n-1.

Finally, you are given qq queries. Each query provides parameters x,l,rx,l,r. You need to compute the value of i=lrpi\sum\limits_{i=l}^r p_i after the first xx operations.

Note: in the queries, xx means the first xx operations, not the first xx groups of operations. That is, a query may happen in the middle of some group of operations.

Input Format

The first line contains three integers n,m,qn,m,q.

The second line contains nn integers, where the ii-th integer denotes pip_i.

The third line contains mm integers, where the ii-th integer denotes aia_i.

The next qq lines each contain three integers x,l,rx,l,r, representing one query.

Output Format

Output qq lines. Each line contains one integer. The integer on the ii-th line is the answer to the ii-th query.

5 2 3
6 2 4 1 3
1 1
1 1 4
2 2 3
4 1 1
6
3
2

Hint

For 100%100\% of the data, $1\le n,m,q\le 1.5\times 10^5,1\le x<n,1\le l\le r\le n-x,1\le p_i\le 10^9,2\sum a_i=n-1$.

Score Time Limit (s)(\operatorname{s}) nn mm qq Special Properties
Subtask1\operatorname{Subtask}1 55 11 100\le 100 None
Subtask2\operatorname{Subtask}2 1010 No special limits No special limits No special limits AB
Subtask3\operatorname{Subtask}3 1515 55 B
Subtask4\operatorname{Subtask}4 11 =1=1 C
Subtask5\operatorname{Subtask}5 None
Subtask6\operatorname{Subtask}6 2020 44 50\le 50
Subtask7\operatorname{Subtask}7 55 No special limits

Special Property A: i,ai=1\forall i,a_i=1.

Special Property B: l=rl=r.

Special Property C: l=1,r=nxl=1,r=n-x.

Sample Explanation

The given operation process is as follows:

6 2 4 1 3

2 2 1 1

2 2 1

2 1

2

Writing special properties separately is only to make the table look nicer...

Thanks to Alfalfa_w\operatorname{A\color{red}lfalfa\_w} for contributing to this problem!

Translated by ChatGPT 5