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<iostream>
#include<random>
#include<vector>
#include<climits>
using namespace std;

// 0-indexed
template<class T, class F>
struct Treap{
    struct Node{
        T val, sum;
        int pri;
        int cnt;
        Node* ch[2];
        Node(T v, int p) : val(v), sum(v), pri(p){
            cnt = 1;
            ch[0] = ch[1] = NULL;
        }
    };

    Node* root;
    vector<T> v;
    F f;    
    T def;  
    Treap(T def, F f) : f(f), def(def) {
        root = NULL;
    }

    int count(Node* t)  {return t==NULL ? 0 : t->cnt;}
    T sum(Node* t)    {return t==NULL ? def : t->sum;}

    Node* update(Node* t){
        t->cnt = count(t->ch[0]) + count(t->ch[1]) + 1;
        t->sum = f(sum(t->ch[0]), f(t->val, sum(t->ch[1])));
        return t;
    }

    Node* rotate(Node* t, int b){
        Node* s = t->ch[b];
        t->ch[b] = s->ch[1-b];
        s->ch[1-b] = t;
        update(t);
        update(s);
        return s;
    }

    Node* insert(Node* t, int k, T val, int pri){
        if(t == NULL)   return new Node(val, pri);
        int leftCnt = count(t->ch[0]);
        int b = k > leftCnt;
        t->ch[b] = insert(t->ch[b], k-(b ? leftCnt+1 : 0), val, pri);
        update(t);
        if(t->ch[b]->pri > t->pri)  t = rotate(t, b);
        return t;
    }
    Node* insert_value(Node* t, T val, int pri){
        if(t == NULL)   return new Node(val, pri);
        int b = val > t->val;
        t->ch[b] = insert_value(t->ch[b], val, pri);
        update(t);
        if(t->ch[b]->pri > t->pri)  t = rotate(t, b);
        return t;
    }
    Node* erase(Node* t, int k, bool me=false){
        if(!me && count(t) <= k)   return t;    // out-of-range
        me |= count(t->ch[0])==k;
        if(me){
            if(t->ch[0]==NULL && t->ch[1]==NULL){
                delete t;
                return NULL;
            }
            int b = (t->ch[0]==NULL ? -1 : t->ch[0]->pri) < (t->ch[1]==NULL ? -1 : t->ch[1]->pri);
            t = rotate(t, b);
            t->ch[1-b] = erase(t->ch[1-b], k, me);
        }else{
            if(count(t->ch[0]) > k){
                t->ch[0] = erase(t->ch[0], k, me);
            }else{  // definitely count(t->ch[0]) < k
                t->ch[1] = erase(t->ch[1], k-count(t->ch[0])-1, me);
            }
        }
        return update(t);
    }
    Node* erase_value(Node* t, T val, bool me=false){
        if(t == NULL)   return NULL;    // there's no node whose value is val
        me |= t->val==val;
        if(me){
            if(t->ch[0]==NULL && t->ch[1]==NULL){
                delete t;
                return NULL;
            }
            int b = (t->ch[0]==NULL ? -1 : t->ch[0]->pri) < (t->ch[1]==NULL ? -1 : t->ch[1]->pri);
            t = rotate(t, b);
            t->ch[1-b] = erase_value(t->ch[1-b], val, me);
        }else{
            if(val < t->val){
                t->ch[0] = erase_value(t->ch[0], val, me);
            }else{
                t->ch[1] = erase_value(t->ch[1], val, me);
            }
        }
        return update(t);
    }

    Node* merge(Node* l, Node* r){
        Node* tmp = new Node(def, INT_MAX);    // rand()は環境依存
        tmp->ch[0] = l;
        tmp->ch[1] = r;
        update(tmp);
        bool me = true;
        return erase(tmp, -1, me);
    }

    // [0, k), [k, n)
    pair<Node*, Node*> split(int k){
        root = insert(root, k, def, INT_MAX);
        return make_pair(root->ch[0], root->ch[1]);
    }

    T get(Node* t, int k){
        int leftCnt = count(t->ch[0]);
        if(leftCnt > k)     return get(t->ch[0], k);
        if(leftCnt == k)    return t->val;
        return get(t->ch[1], k-1-leftCnt);
    }

    void set(Node* t, int k, T newVal){
        if(k < count(t->ch[0])){
            set(t->ch[0], k, newVal);
        }else if(k == count(t->ch[0])){
            t->val = newVal; // or f(t->val, newVal) //
        }else if(k > count(t->ch[0])){
            set(t->ch[1], k-count(t->ch[0])-1, newVal);
        }
        update(t);
    }

    // a, bはt-oriented
    T query(Node* t, int a, int b){
        if(t == NULL)   return def;
        if(a == 0 && count(t) <= b+1)   return t->sum;
        T ret = def;
        int leftCnt = count(t->ch[0]);
        if(a < leftCnt) ret = f(ret, query(t->ch[0], a, b));
        if(a <= leftCnt && leftCnt <= b)    ret = f(ret, t->val);
        if(b > leftCnt) ret = f(ret, query(t->ch[1], max(0, a-leftCnt-1), b-leftCnt-1));
        return ret;
    }

    Node* insert(int k, T val){
        return root = insert(root, k, val, rand());
    }
    Node* erase(int k){
        return root = erase(root, k);
    }
    T get(int k){
        return get(root, k);
    }
    void set(int k, T val){
        set(root, k, val);
    }
    T query(int a, int b){
        return query(root, a, b);
    }
    Node* insert_value(T val){
        return root = insert_value(root, val, rand());
    }
    Node* erase_value(T val){
        return root = erase_value(root, val);
    }
    void flatten(Node* t){
        if(t==NULL) return;
        if(t->ch[0] != NULL)    flatten(t->ch[0]);
        v.push_back(t->val);
        if(t->ch[1] != NULL)    flatten(t->ch[1]);
    }

    vector<T> flatten(){
        v.clear();
        flatten(root);
        return v;
    }
};

int main(){
    auto f = [](int x, int y)->int{
        return min(x, y);
    };
    Treap<int, decltype(f)> t(INT_MAX, f);
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        t.insert(i, a);
    }
    while(q--){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        if(x == 0){
            int tmp = t.get(z);
            t.erase(z);
            t.insert(y, tmp);
        }else if(x == 1){
            printf("%d\n", t.query(y, z));
        }else if(x == 2){
            t.set(y, z);
        }
    }
    return 0;
}