Circular RMQ CodeForces - 52C(线段树)

本文介绍CodeForces 52C问题的解决方案,该问题涉及到在一个循环序列中进行区间加法操作和查询最小值。通过使用线段树并引入懒惰标记来优化区间更新和查询效率。
摘要由CSDN通过智能技术生成

题目链接:点我


You are given circular array a0, a1, ..., an - 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.

Input

The first line contains integer n (1 ≤ n ≤ 200000). The next line contains initial state of the array: a0, a1, ..., an - 1 ( - 106 ≤ ai ≤ 106), ai 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.

Output

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).

Example
Input

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

Output

1
0
0

题意:

给你一个循环序列,有两种操作:
1. 区间(lg, rg) 的所有元素加上V;
2. 查询区间(lg, rg) 的最小值.

思路:

线段树的区间查询与更新,我们用线段树维护区间的最小值,并且设置一个懒惰标记来延迟更新.

代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值