CF1824D.LuoTianyi and the Function
NOI/NOI+/CTSC
通过率:0%
时间限制:7.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
LuoTianyi gives you an array a of n integers and the index begins from 1.
Define g(i,j) as follows:
- g(i,j) is the largest integer x that satisfies ap:i≤p≤j⊆aq:x≤q≤j while i≤j;
- and g(i,j)=0 while i>j.
There are q queries. For each query you are given four integers l,r,x,y, you need to calculate i=l∑rj=x∑yg(i,j).
洛天依给你一个包含 n 个整数的数组 a,数组下标从 1 开始。
定义函数 g(i,j) 如下:
- 当 i≤j 时,g(i,j) 是满足 {ap∣i≤p≤j}⊆{aq∣x≤q≤j} 的最大整数 x;
- 当 i>j 时,g(i,j)=0。
共有 q 次查询。每次查询给出四个整数 l,r,x,y,你需要计算 i=l∑rj=x∑yg(i,j)。
输入格式
The first line contains two integers n and q (1≤n,q≤106) — the length of the array a and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤n) — the elements of the array a.
Next q lines describe a query. The i-th line contains four integers l,r,x,y (1≤l≤r≤n,1≤x≤y≤n) — the integers in the i-th query.
第一行包含两个整数 n 和 q(1≤n,q≤106)—— 分别表示数组 a 的长度以及查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 数组 a 的元素。
接下来的 q 行描述每次查询。第 i 行包含四个整数 l,r,x,y(1≤l≤r≤n,1≤x≤y≤n)—— 第 i 次查询中的参数。
输出格式
Print q lines where i-th line contains one integer — the answer for the i-th query.
输出 q 行,其中第 i 行包含一个整数——即第 i 个查询的答案。
输入输出样例
输入#1
6 4 1 2 2 1 3 4 1 1 4 5 2 3 3 3 3 6 1 2 6 6 6 6
输出#1
6 6 0 6
输入#2
10 5 10 2 8 10 9 8 2 1 1 8 1 1 10 10 2 2 3 3 6 6 6 6 1 1 4 5 4 8 4 8
输出#2
4 2 6 4 80
说明/提示
In the first example:
In the first query, the answer is g(1,4)+g(1,5)=3+3=6.
x=1,2,3 can satisfies ap:1≤p≤4⊆aq:x≤q≤4, 3 is the largest integer so g(1,4)=3.
In the second query, the answer is g(2,3)+g(3,3)=3+3=6.
In the third query, the answer is 0, because all i>j and g(i,j)=0.
In the fourth query, the answer is g(6,6)=6.
In the second example:
In the second query, the answer is g(2,3)=2.
In the fourth query, the answer is g(1,4)+g(1,5)=2+2=4.
在第一个例子中:
第一个查询的答案是 g(1,4)+g(1,5)=3+3=6。
满足 {ap:1≤p≤4}⊆{aq:x≤q≤4} 的 x 可取 1,2,3,其中最大的整数为 3,因此 g(1,4)=3。
第二个查询的答案是 g(2,3)+g(3,3)=3+3=6。
第三个查询的答案是 0,因为对所有 i>j 均有 g(i,j)=0。
第四个查询的答案是 g(6,6)=6。
在第二个例子中:
第二个查询的答案是 g(2,3)=2。
第四个查询的答案是 g(1,4)+g(1,5)=2+2=4。
输入解题思路,AI测评打分。不知道怎么写?