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 <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

struct handler{
	typedef int val_t;
	handler(){}
	static val_t def_val(){ return INF; }
	static val_t update(const val_t &l, const val_t &r){
		return r;
	}
	static val_t merge(const val_t &l, const val_t &r){
		return min(l, r);
	}
};

template<class H>
struct RBST{
	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));
	}
	typedef typename H::val_t val_t;
	struct Node{
		val_t v, sum;
		Node* ch[2];
		int c;
		Node(const val_t &v):v(v), sum(v), c(1){ch[0]=ch[1]=0;}
	};
	typedef pair<Node*, Node*> PNode;
	int count(Node* v){return v ? v->c : 0;}
	val_t val(Node* v){return v ? v->v : H::def_val();}
	val_t sum(Node* v){return v ? v->sum : H::def_val();}
	Node* update(Node *v){
		v->c = count(v->ch[0]) + count(v->ch[1]) + 1;
		v->sum = H::merge(H::merge(sum(v->ch[0]), v->v), sum(v->ch[1]));
		return v;
	}
	Node* merge(Node* l, Node* r){
		if(!l || !r) return !l ? r : l;
		if(xor128() % (count(l) + count(r)) < count(l)){
			l->ch[1] = merge(l->ch[1], r);
			return update(l);
		}else{
			r->ch[0] = merge(l, r->ch[0]);
			return update(r);
		}
	}
	PNode split(Node *v, int k){	// [0, k), [k, n)
		if(!v) return PNode(0, 0);
		if(k <= count(v->ch[0])){
			PNode s = split(v->ch[0], k);
			v->ch[0] = s.second;
			return PNode(s.first, update(v));
		}else{
			PNode s = split(v->ch[1], k - count(v->ch[0]) - 1);
			v->ch[1] = s.first;
			return PNode(update(v), s.second);
		}
	}
	Node* insert(Node *v, int k, Node *t){
		if(!v || !t) return !t ? v : t;
		PNode s = split(v, k);
		return merge(merge(s.first, t), s.second);
	}
	Node* insert(Node *v, int k, const val_t &val){
		return insert(v, k, new Node(val));
	}
	Node* erase(Node* v, int k){
		PNode s = split(v, k);
		PNode p = split(s.second, 1);
		delete p.first;
		return merge(s.first, p.second);
	}
	val_t kth(Node* v, int k){
		if(!v) return H::def_val();
		if(k == count(v->ch[0])) return val(v);
		if(k < count(v->ch[0])) return kth(v->ch[0], k);
		else return kth(v->ch[1], k - count(v->ch[0]) - 1);
	}
	val_t query(Node *v, int l, int r, int k=0){
		if(!v || r <= 0 || count(v) <= l) return H::def_val();
		if(l<=0 && count(v) <= r) return v->sum;
		if(r <= count(v->ch[0])) return query(v->ch[0], l, r, k);
		if(count(v->ch[0]) < l) return query(v->ch[1], l-count(v->ch[0])-1, r-count(v->ch[0])-1, k+count(v->ch[0])+1);
		return H::merge(query(v->ch[0], l, r, k), H::merge(v->v, 
						query(v->ch[1], l-count(v->ch[0])-1, r-count(v->ch[0])-1, k+count(v->ch[0])+1)));
	}
	Node* update(Node* v, int k, const val_t &val){
		if(!v || k < 0 || count(v) <= k) return v;
		if(k == count(v->ch[0])) v->v = H::update(v->v, val);
		else if(k < count(v->ch[0])) v->ch[0] = update(v->ch[0], k, val);
		else v->ch[1] = update(v->ch[1], k-count(v->ch[0])-1, val);
		return update(v);
	}
	friend ostream& operator<<(ostream &os, Node* v){
		if(!v) return os;
		if(v->ch[0]) os << v->ch[0] << ", ";
		os << v->v;
		if(v->ch[1]) os << ", " << v->ch[1];
		return os;
	}
};

int n, q;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> n >> q){
		RBST<handler> rbst;
		RBST<handler>::Node* root = 0;
		REP(i, n){
			int t;
			cin >> t;
			root = rbst.insert(root, i, t);
		}
		REP(i, q){
			int x, y, z;
			cin >> x >> y >> z;
//			cout << root << endl;
			if(x == 0){
				int t = rbst.kth(root, z);
				root = rbst.erase(root, z);
				root = rbst.insert(root, y, t);
			}else if(x == 1){
				cout << rbst.query(root, y, z+1) << endl;
			}else{
				root = rbst.update(root, y, z);
			}
		}
	}
	return 0;
}