测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A8032. Circular RMQ

编程题 普及/提高-

题目描述

You are given circular array $a_{0},a_{1},...,a_{n-1}$ . There are two types of operations with it:

- $inc(lf,rg,v)$ — this operation increases each element on the segment $[lf,rg]$ (inclusively) by $v$ ;
- $rmq(lf,rg)$ — this operation returns minimal value on the segment $[lf,rg]$ (inclusively).

Assume segments to be circular, so if $n=5$ and $lf=3,rg=1$ , it means the index sequence: $3,4,0,1$ .

Write program to process given sequence of operations.
给你一个圆形数组 a0, a1, ..., an - 1 。可以对它进行两种操作:

$inc(lf,rg,v)$ - 此操作会将数据段 [lf, rg] (包括)中的每个元素增加 v ;
$rmq(lf,rg)$ - 此操作会将数据段 [lf, rg] (包括)中的每个元素返回最小值。- 此操作将返回数据段 [lf, rg] (包含)上的最小值。
假设线段是循环的,因此如果 n = 5 和 lf = 3, rg = 1 ,则表示索引序列: 3, 4, 0, 1 .
编写处理给定操作序列的程序。

输入格式

The first line contains integer $n$ ( $1<=n<=200000$ ). The next line contains initial state of the array: $a_{0},a_{1},...,a_{n-1}$ ( $-10^{6}<=a_{i}<=10^{6}$ ), $a_{i}$ are integer. The third line contains integer $m$ ( $0<=m<=200000$ ), $m$ — the number of operartons. Next $m$ lines contain one operation each. If line contains two integer $lf,rg$ ( $0<=lf,rg<=n-1$ ) it means $rmq$ operation, it contains three integers $lf,rg,v$ ( $0<=lf,rg<=n-1;-10^{6}<=v<=10^{6}$ ) — $inc$ operation.
输入
第一行包含整数 $n$ ( $1<=n<=200000$ )。下一行包含数组的初始状态: $a_{0},a_{1},...,a_{n-1}$ ( $-10^{6}<=a_{i}<=10^{6}$ ),$a_{i}$ 为整数。第三行包含整数 $m$ ( $0<=m<=200000$ ), $m$ - 操作数。接下来的 m 行各含一个操作数。如果该行包含两个整数$lf,rg$ ( $0<=lf,rg<=n-1$ ) 表示 rmq 次运算,包含三个整数 $lf,rg,v$ ( $0<=lf,rg<=n-1;-10^{6}<=v<=10^{6}$ ) — $inc$ 次运算。

输出格式

For each $rmq$ operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
输出
为每个 rmq 操作写入结果。请不要在 C++ 中使用 %lld 特指符来读写 64 位整数。最好使用 cout(也可以使用 %I64d)。

输入输出样例

输入 #1
4
1 2 3 4
4
3 0
3 0 -1
0 1
2 1
输出 #1
1
0
0
上一题 去做题 下一题