CF52C.Circular RMQ

提高+/省选-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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−1a_0,\,a_1,\,\dots,\,a_{n-1}。对该数组支持两种操作:

  • inc(lf, rg, v)\text{inc}(lf,\,rg,\,v) —— 该操作将区间 [lf, rg][lf,\,rg](含端点)内的每个元素增加 vv;
  • rmq(lf, rg)\text{rmq}(lf,\,rg) —— 该操作返回区间 [lf, rg][lf,\,rg](含端点)内的最小值。

注意:区间是环形的,因此若 n=5n = 5 且 lf=3, rg=1lf = 3,\,rg = 1,则对应下标序列为:3, 4, 0, 13,\,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 ( - 106 ≤ a__i ≤ 106), 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; - 106 ≤ v ≤ 106) — inc operation.

第一行包含一个整数 $ n (( 1 \leq n \leq 200000 )。第二行包含数组的初始状态:)。 第二行包含数组的初始状态: a_0, a_1, \dots, a_{n-1} (( -10^6 \leq a_i \leq 10^6 $),其中每个 $ a_i $ 均为整数。
第三行包含一个整数 $ m (( 0 \leq m \leq 200000 $),表示操作的数量。
接下来的 $ m $ 行,每行描述一个操作:

  • 若该行包含两个整数 $ lf, rg (( 0 \leq lf, rg \leq n-1 $),则表示一次 rmq 操作;
  • 若该行包含三个整数 $ lf, rg, v (( 0 \leq lf, rg \leq n-1 ;; -10^6 \leq v \leq 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++ 中读写 64 位整数时,请勿使用 %lld 格式说明符;推荐使用 cout(也可使用 %I64d)。

输入输出样例

  • 输入#1

    4
    1 2 3 4
    4
    3 0
    3 0 -1
    0 1
    2 1

    输出#1

    1
    0
    0

输入解题思路,AI测评打分。不知道怎么写?

首页