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 <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <utility>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
#define chmin(x,y) x=min(x,y);
int inf=1e9;
unsigned int xor128(){
	static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
	unsigned int t;
	t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
struct node{	//node of RBST
	int val,mn,size;
	node *lch,*rch;
	node(int v){
		val=mn=v;
		size=1;
		lch=0,rch=0;
	}
};
typedef pair<node*,node*> Pnn;
node *root;
//すべての関数は操作した後の木の親のポインタを返す
node *update(node *x){
	x->size=1;
	x->mn=x->val;
	if(x->lch){
		x->size+=x->lch->size;
		chmin(x->mn,x->lch->mn);
	}
	if(x->rch){
		x->size+=x->rch->size;
		chmin(x->mn,x->rch->mn);
	}
	return x;
}
node *merge(node *x,node *y){
	if(x==0) return y;
	if(y==0) return x;
	int m=x->size,n=y->size;
	if(xor128()%(m+n)<m){
		x->rch=merge(x->rch,y);
		return update(x);
	}else{
		y->lch=merge(x,y->lch);
		return update(y);
	}
}
int count(node *x){
	if(x==0) return 0;
	return x->size;
}
Pnn split(node *x,int pos){		//[,pos),[pos,)
	if(x==0) return Pnn(0,0);
	if(pos<=count(x->lch)){
		Pnn tmp=split(x->lch,pos);
		x->lch=tmp.sc;
		return Pnn(tmp.fs,update(x));
	}else{
		Pnn tmp=split(x->rch,pos-count(x->lch)-1);
		x->rch=tmp.fs;
		return Pnn(update(x),tmp.sc);
	}
}
node *insert(node *x,int pos,int val){
	node *p = new node(val);
	Pnn tmp=split(x,pos);
	node *l=merge(tmp.fs,p),*r=tmp.sc;
	return merge(l,r);
}
node *erase(node *x,int pos){
	Pnn tmp=split(x,pos);
	node *l=tmp.fs,*r=split(tmp.sc,1).sc;
	return merge(l,r);
}
void showtree(node *c){
	if(!c) return;
	cout<<"(";
	showtree(c->lch);
	cout<<"-"<< c->val <<"-";
	showtree(c->rch);
	cout<<")";
}
void query0(int b,int c){
	Pnn x=split(root,c);
	Pnn y=split(x.fs,b);
	Pnn z=split(x.sc,1);
//	show(count(z.sc));
	node *t=merge(y.fs,z.fs);
	node *s=merge(y.sc,z.sc);
//	showtree(t);puts("");
//	showtree(s);puts("");
	root=merge(t,s);
}
void query1(int b,int c){
	Pnn x=split(root,b);
	Pnn y=split(x.sc,c+1-b);
//	show(count(y.fs));
	cout<<y.fs->mn<<endl;
	root=merge(x.fs,merge(y.fs,y.sc));
}
void query2(int b,int c){
	root=erase(root,b);
	root=insert(root,b,c);
}
int main(){
	int N,Q;
	cin>>N>>Q;
	rep(i,N){
		int a;
		scanf("%d",&a);
		root=insert(root,i,a);
	}
//	show(count(root));
//	showtree(root);puts("");
	rep(i,Q){
		int a,b,c;
		cin>>a>>b>>c;
		if(a==0) query0(b,c);
		if(a==1) query1(b,c);
		if(a==2) query2(b,c);
//		showtree(root);puts("");
	}
}