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>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

//RBST 実装

//構造体
struct node_t{
	int val;
	node_t *ch[2];
	int cnt;
	int sum;
	
	node_t(int v): val(v),cnt(1),sum(v) {
		ch[0] = ch[1] = NULL;
	}
};
int count(node_t *t){
	return !t ? 0 : t->cnt;
}
int sum(node_t *t){
	return !t ? mod : t->sum;
}
node_t *update(node_t *t){
	t->cnt = count(t->ch[0])+count(t->ch[1])+1;
	t->sum = min(min(sum(t->ch[0]),sum(t->ch[1])),t->val);
	return t;
}
//乱数
unsigned long xor128() {
  static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}
//merge-split で実装
node_t *merge(node_t *l,node_t *r){
	if(!l || !r) return !l ? r: l;
	
	if(xor128()%(l->cnt+r->cnt) < l->cnt){
		l->ch[1] = merge(l->ch[1],r);
		return update(l);
	}
	else{
		r->ch[0] = merge(l,r->ch[0]);
		return update(r);
	}
}
pair<node_t*,node_t*>split(node_t *t,int k){ //[0,k) [k,n)
	if(!t) return mp((node_t*)NULL,(node_t*)NULL);
	if(k <= count(t->ch[0])){
		pair<node_t*,node_t*>s = split(t->ch[0],k);
		t->ch[0] = s.sc;
		return mp(s.fi,update(t));
	}
	else{
		pair<node_t*,node_t*>s = split(t->ch[1],k-count(t->ch[0])-1);
		t->ch[1] = s.fi;
		return mp(update(t),s.sc);
	}
}
node_t *root = (node_t*)NULL;
node_t *insert(node_t *nd,int k,int val){
	pair<node_t*,node_t*>s = split(nd,k);
	nd = merge(s.fi,new node_t(val));
	nd = merge(nd,s.sc);
	return update(nd);
}
node_t *erase(node_t *nd,int k){
	pair<node_t*,node_t*>s,t;
	t = split(nd,k+1);
	s = split(t.fi,k);
	nd = merge(s.fi,t.sc);
	return update(nd);
}
node_t *shift(node_t *nd,int a,int b){
    pair<node_t*,node_t*>s,t,u;
    s = split(nd,b+1);
    t = split(s.first,b);
    u = split(t.first,a);
    nd = merge(u.first,t.second);
    nd = merge(nd,u.second);
    nd = merge(nd,s.second);
    return nd;
}
int query(node_t* root,int a,int b){
    int sz = count(root);
    if(a>=sz || a>b || b<0) return mod;
    if(a<=0 && sz-1<=b) {return sum(root);}
    a = max(0,a); b = min(b,sz-1);
    int x = count(root->ch[0]);
    int L = query(root->ch[0],a,b);
    int R = query(root->ch[1],a-x-1,b-x-1);
    int ret = min(L,R);
    if(a<=x&&x<=b) ret = min(ret,root->val);
    return ret;
}
void print(node_t* cur,int val){
    cout << cur->val <<" " << val << endl;
    if(cur->ch[0] != (node_t*)NULL) print(cur->ch[0],cur->val);
    if(cur->ch[1] != (node_t*)NULL) print(cur->ch[1],cur->val);
}

int n,q;
int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		int a; scanf("%d",&a); root = insert(root,i,a);
	}
	for(int i=0;i<q;i++){
		int x; scanf("%d",&x);
		if(x == 0){
			int a,b; scanf("%d%d",&a,&b);
			root = shift(root,a,b);
		}
		else if(x == 1){
			int a,b; scanf("%d%d",&a,&b);
			printf("%d\n",query(root,a,b));
		}
		else{
			int a,b; scanf("%d%d",&a,&b);
			root = erase(root,a);
			root = insert(root,a,b);
		}
	}
}