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 syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Splay_Tree{
	private:
	int n;
	vi L,R,par,val,date,sub;
	void Fix(int k){
		sub[k]=sub[L[k]]+sub[R[k]]+1;
	date[k]=min({val[k],date[L[k]],date[R[k]]});
	}
	void Set(int k,int l,int r,int p,bool B=0){
		if(B) swap(l,r);
		L[k]=l;R[k]=r;par[k]=p;
		if(l!=n) par[l]=k;
		if(r!=n) par[r]=k;
		Fix(k);
	}
	void Clear(int v){
		L[v]=R[v]=par[v]=n;
		val[v]=date[v]=inf;
		sub[v]=1;
	}
	int Ch(int v,bool B){return (B?R[v]:L[v]);}
	int Splay(int u){
		while(par[u]!=n){
			int v=par[u],w=par[v];
			bool A=(R[v]==u),B=(R[w]==v);
			if(w==n){
				Set(v,Ch(u,!A),Ch(v,!A),u,A);
				Set(u,Ch(u,A),v,n,A);
				continue;
			}
			int w_=par[w];
			if(w_!=n){
				if(L[w_]==w) L[w_]=u;
				else R[w_]=u;
			}
			if(A^B){
				Set(w,Ch(w,A),Ch(u,A),u,A);
				Set(v,Ch(u,!A),Ch(v,!A),u,A);
				Set(u,w,v,w_,A);
			}
			else{
				Set(w,Ch(v,!A),Ch(w,!A),v,A);
				Set(v,Ch(u,!A),w,u,A);
				Set(u,Ch(u,A),v,w_,A);
			}
		}
	}
	public:
	Splay_Tree(int N){
		n=N;
		L=R=par=vi(n+2,n);
		val=date=vi(n+2,inf);
		sub=vi(n+2,1);
		sub[n]=0;
		for(int i=1;i<n;i++) Set(i,i-1,n,i+1);
	}
	int Find(int v,int k){
		Splay(v);
		while(1){
			int t=sub[L[v]];
			if(t==k) break;
			if(k<t) v=L[v];
			else k-=t+1,v=R[v];
		}
		Splay(v);
		return v;
	}
	void Update(int k,int x){
		k=Find(0,k);
		val[k]=x;date[k]=min(date[k],x);
	}
	int Sub(int v){
		Splay(v);
		return sub[v];
	}
	void Insert(int v,int k,int id){
//		cout<<v<<' '<<k<<' '<<id<<endl;
		int N=Sub(v);
		if(!k||k==N){
			k=Find(v,(k?k-1:0));
			Set(id,n,k,n,k);
			return;
		}
		int l=Find(v,k-1),r=Find(v,k);
		Splay(l);Splay(r);
//		cout<<l<<' '<<r<<endl;
		par[l]=par[r]=id;
		Set(r,n,R[r],id);
		Set(id,l,r,n);
	}
	void Erase(int v,int k){
		if(!k){
			Clear(Find(v,k));
			return;
		}
		int l=Find(v,k-1),r=Find(v,k);
		Splay(l);Splay(r);
		if(R[r]!=n) par[R[r]]=l;
		Set(l,L[l],R[r],n);
		Clear(r);
	}
	void Erase_id(int v){
		Splay(v);
		Erase(v,sub[L[v]]);
	}
	void Merge(int l,int r){
//		cout<<l<<' '<<r<<endl;
		Splay(l);Splay(r);
		Set(n+1,l,r,n);
		Erase(l,sub[l]);
//		for(int i=0;i<n+2;i++) Open(i);
//		cout<<endl;
	}
	int Split(int v,int k){
		Insert(v,k,n+1);
//		cout<<v<<' '<<k<<endl;
//		for(int i=0;i<n+2;i++) Open(i);
//		cout<<endl;
		int t=Find(v,k+1);
//		for(int i=0;i<n+2;i++) Open(i);
//		cout<<endl;
		Splay(n+1);
		if(L[n+1]!=n) par[L[n+1]]=n;
		if(R[n+1]!=n) par[R[n+1]]=n;
		Clear(n+1);
//		for(int i=0;i<n+2;i++) Open(i);
//		cout<<endl;
//		cout<<t<<"!!!!"<<endl;
		return t;
	}
	int Query(int l,int r){
		if(l>=r) return inf;
		l=Find(0,l);if(r!=n) r=Find(0,r);
		Splay(l);if(r!=n) Splay(r);
		return min(val[l],date[R[l]]);
	}
	void Open(int v){
		cout<<v<<':'<<(L[v]==n?-1:L[v])<<' '<<(R[v]==n?-1:R[v])<<' '<<(par[v]==n?-1:par[v])<<' '<<sub[v]<<' '<<val[v]<<' '<<date[v]<<endl;
	}
};

int n,q;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>q;
	Splay_Tree sp(n+2);
	for(int i=1;i<=n;i++){
		int A;
		cin>>A;
		sp.Update(i,A);
	}
	for(int i=0;i<q;i++){
		int t,x,y;
		cin>>t>>x>>y;
		if(!t){
			int C=sp.Split(0,y+2),B=sp.Split(0,y+1),A=sp.Split(0,x+1);
//			cout<<A<<' '<<B<<' '<<C<<endl;
			sp.Merge(0,B);sp.Merge(B,A);sp.Merge(A,C);
		}
		else if(t==1) cout<<sp.Query(x+1,y+2)<<endl;
		else sp.Update(x+1,y);
//		for(int j=0;j<n+4;j++) sp.Open(j);
//		cout<<endl;
	}
}