Codeforces Testing Round 1
C
Circular RMQ
Codeforces
2200
原题
← B→
翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

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

翻译中…

样例

Input #1
4
1 2 3 4
4
3 0
3 0 -1
0 1
2 1
Output #1
1
0
0
InputCopy OutputCopy
题目信息
题号
52C
时间限制
1.5 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。