Go: package main

// packed from [splaytree.go main.rmq.go splaytree_debug.go] with goone.

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

type SplayTreeNode struct {
	parent, left, right *SplayTreeNode

	size    int
	value   int
	minimum int
}

func newSplayTreeNode(v int) *SplayTreeNode {
	return &SplayTreeNode{value: v}
}

func (node *SplayTreeNode) rotate() {
	var pp, p, c *SplayTreeNode
	p = node.parent
	pp = p.parent
	if pp != nil && pp.left == p {
		pp.left = node
	}
	if pp != nil && pp.right == p {
		pp.right = node
	}
	node.parent = pp
	if p.left == node {
		c = node.right
		node.right = p
		p.left = c
	} else {
		c = node.left
		node.left = p
		p.right = c
	}
	p.parent = node
	if c != nil {
		c.parent = p
	}
	p.update()
	node.update()
}

func (node *SplayTreeNode) state() int {
	if node.parent == nil {
		return 0
	}
	if node.parent.left == node {
		return -1
	} else if node.parent.right == node {
		return 1
	}
	return 0
}

func (node *SplayTreeNode) splay() {
	for node.state() != 0 {
		if node.parent.state() == 0 {
			node.rotate()
			return
		}
		if node.state() == node.parent.state() {
			node.parent.rotate()
			node.rotate()
		} else {
			node.rotate()
			node.rotate()
		}
	}
}

func (node *SplayTreeNode) update() {
	node.size = 1
	node.minimum = node.value
	if node.left != nil {
		node.size += node.left.size
		node.minimum = min(node.minimum, node.left.minimum)
	}
	if node.right != nil {
		node.size += node.right.size
		node.minimum = min(node.minimum, node.right.minimum)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (node *SplayTreeNode) Get(idx int) *SplayTreeNode {
	cur := node
	for true {
		lSize := 0
		if cur.left != nil {
			lSize = cur.left.size
		}
		if idx < lSize {
			cur = cur.left
		}
		if lSize == idx {
			cur.splay()
			return cur
		}
		if idx > lSize {
			cur = cur.right
			idx = idx - lSize - 1
		}
	}
	return nil
}

func mergeSplayNode(l, r *SplayTreeNode) (root *SplayTreeNode) {
	if l == nil {
		return r
	}
	if r == nil {
		return l
	}
	root = l.Get(l.size - 1)
	root.right = r
	r.parent = root
	root.update()
	return root
}

func (node *SplayTreeNode) Split(leftCount int) (left *SplayTreeNode, right *SplayTreeNode) {
	root := node.Get(leftCount)
	lRoot, rRoot := root.left, root

	rRoot.left = nil
	if lRoot != nil {
		lRoot.parent = nil
	}
	rRoot.update()
	return lRoot, rRoot
}

func splayTreeInsert(t *SplayTreeNode, idx int, node *SplayTreeNode) (root *SplayTreeNode) {
	l, r := t.Split(idx)
	return mergeSplayNode(
		mergeSplayNode(l, node),
		r,
	)
}

func removeSplayTree(t *SplayTreeNode, idx int) (root *SplayTreeNode, removed *SplayTreeNode) {
	target := t.Get(idx)
	l, r := target.left, target.right
	if l != nil {
		l.parent = nil
	}
	if r != nil {
		r.parent = nil
	}
	target.left = nil
	target.right = nil
	target.update()
	return mergeSplayNode(l, r), target
}

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	q := scanInt(sc)
	table := newDebugNodeSlice(200001)
	for i := 0; i < n; i++ {
		table.l[i].parent = &table.l[i+1]
		table.l[i+1].left = &table.l[i]
		table.l[i].update()
		table.l[i+1].update()
	}
	var root *SplayTreeNode = &table.l[n]
	for i := 0; i < n; i++ {
		table.l[i].value = scanInt(sc)
		table.l[i].update()
	}
	table.l[n].update()
	for i := 0; i < q; i++ {
		switch scanInt(sc) {
		case 0:
			root = shift(root, scanInt(sc), scanInt(sc))
		case 1:
			l := scanInt(sc)
			r := scanInt(sc)
			tmp, rRoot := root.Split(r + 1)
			lRoot, cRoot := tmp.Split(l)
			fmt.Println(cRoot.minimum)
			root = mergeSplayNode(mergeSplayNode(lRoot, cRoot), rRoot)
		case 2:
			root = root.Get(scanInt(sc))
			root.value = scanInt(sc)
			root.update()
		}
	}
}


C++: #include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};


// Treap based on merge and split 
// each operation 
// set parameter
const int inf=1<<29;
const int nmax=1000010;

mt19937 mt;   
uniform_real_distribution<double> rnd(0.0,1.0);

struct Node{
	int val,cnt,min,add,rev;
	Node *lch=nullptr,*rch=nullptr;
	double pri;
	Node(){}
	Node(int v): val(v),cnt(1),min(v),add(0),rev(0),pri(rnd(mt)){}
};

// memory pool
int total=0;
Node pool[nmax];

Node* create(int v){
	pool[total]=Node(v);
	return &(pool[total++]);	
}

// helper function
int val(Node* x){assert(x!=nullptr); return x->val+x->add;}
int cnt(Node* x){return (x==nullptr)?0:x->cnt;}
int min(Node* x){return (x==nullptr)?inf:x->min+x->add;}

Node* update(Node* x){
	if(x==nullptr) return x;
	
	x->cnt=1+cnt(x->lch)+cnt(x->rch);
	x->min=min({val(x),min(x->lch),min(x->rch)});

	if(x->add) {
		x->val+=x->add;
		if(x->lch!=nullptr) x->lch->add+=x->add;
		if(x->rch!=nullptr) x->rch->add+=x->add;
		x->add=0;
	}

	if(x->rev) {
		swap(x->lch,x->rch);
		if(x->lch!=nullptr) x->lch->rev^=true;
		if(x->rch!=nullptr) x->rch->rev^=true;
		x->rev=false;
	}
	
	return x;
}

Node* merge(Node* l,Node* r){
	l=update(l),r=update(r);
	if(l==nullptr) return r;
	if(r==nullptr) return l;
	
	if(l->pri > r->pri){
		l->rch = merge(l->rch,r);
		return update(l);
	}else{
		r->lch = merge(l,r->lch);
		return update(r);
	}
}

tuple<Node*,Node*> split(Node* x,int k){ //[0,k) [k,n)
	if(update(x)==nullptr) return make_tuple(nullptr,nullptr);

	Node *l,*r;
	if(k<=cnt(x->lch)){
		tie(l,r)=split(x->lch,k);
		x->lch=r;
		return make_tuple(update(l),update(x));
	}else{
		tie(l,r)=split(x->rch,k-cnt(x->lch)-1);
		x->rch=l;
		return make_tuple(update(x),update(r));
	}
}

Node* range_merge(Node* left,Node* tar,Node* right){
	return merge(left,merge(tar,right));
}

tuple<Node*,Node*,Node*> range_split(Node* t,int l,int r){
	Node *left,*tar,*right; 
	tie(tar,right)=split(t,r);
	tie(left,tar)=split(tar,l);
	return make_tuple(left,tar,right);
}

void insert(Node* t,int k,int v){
	Node *left,*right,*tar=create(v);	
	tie(left,right)=split(t,k);
	t=range_merge(left,tar,right);
}

void erase(Node* t,int k){
	Node *left,*tar,*right;
	tie(left,tar,right)=range_split(t,k,k+1);
	t=merge(left,right);
}

void add(Node* t,int l,int r,int a){
	Node *left,*tar,*right; 
	tie(left,tar,right)=range_split(t,l,r);
	tar->add+=a;
	t=range_merge(left,tar,right);
}

void rev(Node* t,int l,int r){
	Node *left,*tar,*right; 
	tie(left,tar,right)=range_split(t,l,r);
	tar->rev^=true;
	t=range_merge(left,tar,right);
}

void rot(Node* t,int l,int r,int k){
	Node *left,*tar,*right; 
	tie(left,tar,right)=range_split(t,l,r);
	Node *tar_l,*tar_r;
	tie(tar_l,tar_r)=split(tar,cnt(tar)-k);
	tar=merge(tar_r,tar_l);
	t=range_merge(left,tar,right);
}

int min(Node* t,int l,int r){
	Node *left,*tar,*right; 
	tie(left,tar,right)=range_split(t,l,r);
	int ret=tar->min;
	t=range_merge(left,tar,right);
	return ret;
}

int main(void){
	int n,q;
	cin >> n >> q;
	
	Node* t=nullptr;

	rep(i,n){
		int in;
		cin >> in;
		t=merge(t,create(in));
	}	

	rep(loop,q){
		int type,a,b;
		cin >> type >> a >> b;
		if(type==0)
			shift(t,a,b+1);
		else if(type==1)
			cout << min(t,a,b+1) << endl;
		else
			change(t,a,b);
	}
	return 0;
}