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 rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Treap
//-------------------------------------------------
template <class T, class E=T>
class Treap
{
public:
    struct Node {
        Node *child[2];
        T val,sum;
        bool rev;
        uint32_t pri;
        int weight;
        Node(){}
        Node(T val, uint32_t pri):val(val),sum(val),pri(pri){
            child[0]=child[1]=nullptr;
            rev = 0; weight=1;
        }
    };
    using np = Node*;
private:
    // functions *
    inline T f(T x, T y){return min(x,y);}
    // inline T g(T x, E y){return ;}
    // inline E h(E x, E y){return ;}
    const int e = 1e9;

    int n,ptr;
    vector<Node> buf;

    uint32_t xorshift(){
        static uint32_t x = 123456789;
        static uint32_t y = 362436069;
        static uint32_t z = 521288629;
        static uint32_t w = 88675123;
        uint32_t t;
        t = x ^ (x<<11);
        x = y; y = z; z = w;
        w ^= t ^ (t>>8) ^ (w>>19);
        return w;
    }

    inline np make_node(const T &val, uint32_t pri, bool dummy){
        assert(ptr<n);
        np ret = &(buf[ptr]=Node(val,pri));
        if (!dummy) ptr++;
        return ret;
    }
    inline T sum(np t){return t ? t->sum : e;}
    inline np update(np t){
        t->weight = weight(t->child[0])+weight(t->child[1])+1;
        t->sum = f(f(sum(t->child[0]),t->val),sum(t->child[1]));
        return t;
    }
    inline void push(np t){
        // propagate to child
        if (t->rev){
            swap(t->child[0], t->child[1]);
            if (t->child[0]) t->child[0]->rev=true;
            if (t->child[1]) t->child[1]->rev=true;
            t->rev = false;
        }
    }
    inline np rotate(np t, int dir){
        np s = t->child[dir];
        t->child[dir] = s->child[1-dir];
        s->child[1-dir] = t;
        update(t); update(s);
        return s;
    }
    np insert(np t, int k, const T &val, uint32_t pri, bool dummy=false){
        if (!t) return make_node(val,pri,dummy);
        push(t);
        int c=weight(t->child[0]), dir=k>c;
        t->child[dir] = insert(t->child[dir],k-dir*(c+1),val,pri,dummy);
        update(t);
        if (t->pri >= t->child[dir]->pri) t = rotate(t,dir);
        return t;
    }
    np _erase(np t, int k, bool rot){
        if (!t) return nullptr;
        push(t);
        int w0=weight(t->child[0]);
        rot = rot||w0==k;
        int dir = k>w0;
        if (rot){
            if (!t->child[0]) return t->child[1];
            if (!t->child[1]) return t->child[0];
            dir = (t->child[0]->pri)<(t->child[1]->pri);
            push(t->child[1-dir]);
            t = rotate(t,1-dir);
            w0=weight(t->child[0]);
        }
        t->child[dir] = _erase(t->child[dir],k-dir*(w0+1),rot);
        update(t);
        return t;
    }
public:
    Treap(int n):n(n),buf(n),ptr(0){};
    inline int weight(np t){return t ? t->weight : 0;}
    void insert(np &t, int k, const T &val){ t = insert(t,k,val,xorshift());}
    void erase(np &t, int k){ t = _erase(t,k,false);}
    void push_back(np &t, const T &val){ t = insert(t,weight(t),val,xorshift());}

    pair<np,np> split(np t, int k){
        t = insert(t,k,0,0,true);
        return make_pair(t->child[0], t->child[1]);
    }
    np merge(np left, np right){
        np t = make_node(0,0,true);
        t->child[0] = left; t->child[1] = right;
        update(t);
        return _erase(t,weight(t->child[0]),true);
    }
    void reverse(np &t, int a, int b){
        auto p = split(t,a);
        auto q = split(p.second,b-a);
        q.first->rev = true;
        t = merge(merge(p.first,q.first),q.second);
    }
    void rotate(np &t, int a, int b, int c){
        auto p = split(t,a);
        auto q = split(p.second,c-a);
        auto r = split(q.first,b-a);
        t = merge(merge(merge(p.first,r.second),r.first),q.second);
    }
    T query(np &t, int a, int b){
        auto p = split(t,a);
        auto q = split(p.second,b-a);
        T ret = sum(q.first);
        t = merge(p.first,merge(q.first,q.second));
        return ret;
    }
    void assign(np t, int k, T x){
        assert(t); push(t);
        int c=weight(t->child[0]), dir=k>c;
        if (c==k){
            t->val = x; update(t);
            return;
        }
        assign(t->child[dir],k-dir*(c+1),x);
        update(t);
    }
    T get(np t, int k){
        assert(t); push(t);
        int c=weight(t->child[0]), dir=k>c;
        if (c==k) return t->val;
        return get(t->child[dir],k-dir*(c+1));
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin>>N>>Q;
    Treap<int> treap(N+Q+1);
    Treap<int>::np root = nullptr;
    rep(i,N){
        int a; cin>>a;
        treap.pb(root,a);
    }
    while(Q--){
        int x,y,z; cin>>x>>y>>z;
        if (x==0) treap.rotate(root,y,z,z+1);
        if (x==1) cout<<treap.query(root,y,z+1)<<"\n";
        if (x==2) treap.assign(root,y,z);
    }
    return 0;
}