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;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct SplayTree{
	struct Node{
		int x,sz,mini;
		Node *l,*r,*p;
		Node(int x,Node *p):x(x),sz(1),mini(x),p(p),l(NULL),r(NULL){}
	};

	Node *root;

	SplayTree():root(NULL){}

	Node* Update(Node *n){
		if(!n) return NULL;
		n->mini=n->x;
		n->sz=1;
		if(n->l){
			n->mini=min(n->mini,n->l->mini);
			n->sz+=n->l->sz;
		}
		if(n->r){
			n->mini=min(n->mini,n->r->mini);
			n->sz+=n->r->sz;
		}
		return n;
	}

	int Size(Node *t){
		if(!t) return 0;
		return t->sz;
	}

	void Rotate(Node *n){
		Node *p=n->p,*pp=p->p;

		n->p=pp;
		if(pp==NULL) root=n;
		else{
			if(p==pp->l) pp->l=n;
			else pp->r=n;
		}

		p->p=n;
		if(p->l==n){
			p->l=n->r;
			if(n->r!=NULL) n->r->p=p;
			n->r=p;
		}else{
			p->r=n->l;
			if(n->l!=NULL) n->l->p=p;
			n->l=p;
		}
		Update(p);
		Update(n);
	}

	void Splay(Node *n){
		while(n&&n->p){
			Node *p=n->p,*pp=p->p;
			if(!pp){
				//zig
				Rotate(n);
			}else{
				if(pp->l==p){
					if(p->l==n){
						//zig-zig
						Rotate(p);
						Rotate(n);
					}else if(p->r==n){
						//zig-zag
						Rotate(n);
						Rotate(n);
					}
				}else if(pp->r==p){
					if(p->l==n){
						//zig-zag
						Rotate(n);
						Rotate(n);
					}else if(p->r==n){
						//zig-zig
						Rotate(p);
						Rotate(n);
					}
				}
			}
		}
	}

	Node* Find(Node *t,int k){	//1-indexed
		if(!t) return NULL;
		int l_sz=Size(t->l),r_sz=Size(t->r);

		if(l_sz+1==k) return t;
		if(k<=l_sz) return Find(t->l,k);
		return Find(t->r,k-l_sz-1);
	}

	Node *Max(Node *t){
		if(!t) return NULL;
		while(t->r) t=t->r;
		return t;
	}

	void Insert(Node *t,int k,int x){
		Node *p=Find(t,k);
		if(p==NULL){ //木が空
			root=new Node(x,NULL);
			return;
		}

		Splay(p);
		Node *n=new Node(x,p);
		n->r=p->r;
		if(p->r) p->r->p=n;
		p->r=n;
		Splay(n);
	}

	void Erase(Node *t,int k){
		Node *n=Find(t,k+1);
		if(!n) return;
		Splay(n);
		
		if(n->l==NULL){
			root=n->r;
			n->r->p=NULL;
			delete n;
			return;
		}

		Node *new_root=Max(n->l);
		Node *p=new_root->p;
		new_root->p->r=NULL;
		new_root->p=NULL;
		new_root->r=n->r;
		n->r->p=new_root;
		root=new_root;
		while(p!=NULL){
			Update(p);
			p=p->p;
		}
	}

	Node* Merge(Node *l,Node *r){
		if(l==NULL) return root=r;
		if(r==NULL) return root=l;
		l=Max(l);
		Splay(l);
		Splay(r);
		l->r=r;
		r->p=l;
		return root=Update(l);
	}

	pair<Node*,Node*> Split(Node *t,int k){ //[,k),[k,)
		if(!t) return make_pair((Node*)NULL,(Node*)NULL);
		if(k==0) return make_pair((Node*)NULL,t);
		if(k==Size(t)) return make_pair(t,(Node*)NULL);
		if(k<0||Size(t)<k){
			dump("split failed");
			dump(Size(t));
			return make_pair((Node*)NULL,(Node*)NULL);
		}
		Node *l=Find(t,k);
		Splay(l);
		Node *r=l->r;
		l->r=NULL;
		if(r) r->p=NULL;
		return make_pair(Update(l),r);
	}

	void Query0(int l,int r){
		pair<Node*,Node*> p1=Split(root,l);
		pair<Node*,Node*> p2=Split(p1.second,r-l-1);
		pair<Node*,Node*> p3=Split(p2.second,1);
		
		//[p1.first,p2.first,p3.first,p3.second]
		dump(Size(p1.first));
		dump(Size(p2.first));
		dump(Size(p3.first));
		dump(Size(p3.second));
		
		Merge(Merge(p1.first,p3.first),Merge(p2.first,p3.second));
	}

	void Query1(int l,int r){
		cout << Query1Sub(l,r,root,0,Size(root)) << endl;
	}

	int Query1Sub(int a,int b,Node *n,int l,int r){
		if(!n||r<=a||b<=l) return INF;
		if(a<=l&&r<=b) return n->mini;
		int res=INF,k=l+Size(n->l);
		if(a<=k&&k<b) res=n->x;
		return min({res,Query1Sub(a,b,n->l,l,r-Size(n->r)-1),Query1Sub(a,b,n->r,l+Size(n->l)+1,r)});
	}

	void Query2(int k,int x){
		Node *n=Find(root,k+1);
		Splay(n);
		n->x=x;
		Update(n);
	}
};

void Solve(){
	int n,q;
	cin >> n >> q;

	SplayTree t;
	rep(i,0,n){
		int a; cin >> a;
		t.Insert(t.root,i,a);
	}

	rep(i,0,q){
		dump(t.root->sz);
		int x,y,z;
		cin >> x >> y >> z;
		if(x==0) t.Query0(y,z+1);
		else if(x==1) t.Query1(y,z+1);
		else t.Query2(y,z);
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}