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;

const int INF = 1001001001;
template <typename T>
class Treap {
public:
    struct Node {
        T val;
        T data;
        Node *left, *right;
        int priority;
        size_t size;
        Node(T val) : val(val), data(val), size(1) {
            priority = rand();
            left = right = nullptr;
        }
        ~Node() { delete left; delete right; }
    };

    Node *root;
    Treap(Node *n) : root(n) {}
public:
    Treap() : root(nullptr) {}
    virtual ~Treap() { delete root; }

    size_t size() { return size(root); }
    size_t size(Node *v) { return !v ? 0 : v->size; }
    T data(Node *v) { return !v ? INF : v->data; }

    Node *update(Node *v) {
        if (!v) return nullptr;
        v->size = size(v->left) + size(v->right) + 1;
        T tmp = min(data(v->left), data(v->right));
        v->data = min(v->val, tmp);
        return v;
    }

    Node *merge(Node *l, Node *r) {
        if (!l or !r)
            return l ? l : r;
        if (l->priority > r->priority) {
            l->right = merge(l->right, r);
            return update(l);
        } else {
            r->left = merge(l, r->left);
            return update(r);
        }
    }
    // [0, k), [k, n)
    pair<Node*, Node*> split(Node *v, size_t k) {
        if (!v) return {nullptr, nullptr};
        size_t ls = size(v->left);
        if (k <= ls) {
            auto s = split(v->left, k);
            v->left = s.second;
            return {s.first, update(v)};
        } else {
            auto s = split(v->right, k - ls - 1);
            v->right = s.first;
            return {update(v), s.second};
        }
    }

    void insert(size_t k, T val) {
        root = insert(root, k, val);
    }
    Node *insert(Node *t, size_t k, T val) {
        auto s = split(t, k);
        t = merge(s.first, new Node(val));
        t = merge(t, s.second);
        return update(t);
    }

    void erase(size_t k) {
        root = erase(root, k);
    }
    Node *erase(Node *t, size_t k) {
        Node *l, *m, *r;
        tie(l, r) = split(t, k + 1);
        tie(l, m) = split(l, k);
        t = merge(l, r);
        delete m;
        return update(t);
    }

    T &find(size_t k) { 
        return find(root, k)->val;
    }
    Node *find(Node *t, size_t k) {
        size_t ls = size(t->left);
        if (ls == k) return t;
        if (k < ls) return find(t->left, k);
        return find(t->right, k - ls - 1);
    }
};

template <typename T>
class TreapArray : public Treap<T> {
public:
    void push_back(T value) { this->insert(this->size(this->root), value); }
    void push_front(T value) { this->insert(0, value); }
    void pop_back() { this->erase(this->size(this->root) - 1); }
    void pop_front() { this->erase(0); }
    T &back() { return this->find(this->size(this->root) - 1); }
    T &front() { return this->find(0); }
};

template <typename T>
class TreapOrderedSet : public Treap<T> {
    using Node = typename Treap<T>::Node;
public:
    TreapOrderedSet() : Treap<T>() {}
    TreapOrderedSet(Node *n) : Treap<T>(n) {}
    
    pair<TreapOrderedSet, TreapOrderedSet> split_less(const T &x) {
        auto p = __split(this->root, x, false);
        return {TreapOrderedSet(p.first), TreapOrderedSet(p.second)};
    }
    pair<TreapOrderedSet, TreapOrderedSet> split_leq(const T &x) {
        auto p = __split(this->root, x, true);
        return {TreapOrderedSet(p.first), TreapOrderedSet(p.second)};
    }
    pair<Node*, Node*> __split(Node *n, const T &x, bool leq) {
        if (n == nullptr) return {nullptr, nullptr};
        if (n->val < x || (leq && n->val == x)) {
            auto p = __split(n->right, x, leq);
            n->right = p.first;
            return {this->update(n), p.second};
        } else {
            auto p = __split(n->left, x, leq);
            n->left = p.second;
            return {p.first, this->update(n)};
        }
    }

    void insert(const T &x) { this->root = __insert(this->root, x); }
    Node *__insert(Node *n, const T &x) {
        auto p = __split(n, x, false);
        return this->merge(this->merge(p.first, new Node(x)), p.second);
    }

    void erase_one(const T &x) {
        assert(contains(this->root, x));
        this->root = __erase_one(this->root, x);
    }
    Node *__erase_one(Node *n, const T &x) {
        Node *l, *m, *r;
        tie(l, r) = __split(n, x, false);
        tie(m, r) = this->split(r, 1);
        return this->merge(l, r);
    }

    void erase_all(const T &x) { this->root = __erase_all(this->root, x); }
    Node *__erase_all(Node *n, const T &x) {
        Node *l, *m, *r;
        tie(l, r) = __split(n, x, false);
        tie(m, r) = __split(r, x, true);
        return this->merge(l, r);
    }

    size_t count_less(const T &x) { return __count(this->root, x, false); }
    size_t count_leq(const T &x) { return __count(this->root, x, true); }
    size_t __count(const Node *n, const T &x, bool leq) {
        if (n == nullptr) return 0;
        if (n->val < x || (leq && n->val == x)) {
            return this->size(n->left) + 1 + __count(n->right, x, leq);
        } else {
            return __count(n->left, x, leq);
        }
    }
    size_t count(const T &x) { return count_leq(x) - count_less(x); }

    bool contains(const T &x) { return __contains(this->root, x); }
    bool __contains(const Node *n, const T &x) {
        if (n == nullptr) return false;
        if (n->val < x) {
            return __contains(n->right, x);
        } else if (n->val == x) {
            return true;
        } else {
            return __contains(n->left, x);
        }
    }

    T lower_bound(const T &x) { return __lower_bound(this->root, x)->val; }
    Node *__lower_bound(Node *n, const T &x) {
        if (n == nullptr) return nullptr;
        if (n->val < x) {
            return __lower_bound(n->right, x);
        } else {
            Node *res = __lower_bound(n->left, x);
            return res ? res : n;
        }
    }

    T upper_bound(const T &x) { return __upper_bound(this->root, x)->val; }
    Node *__upper_bound(Node *n, const T &x) {
        if (n == nullptr) return nullptr;
        if (n->val <= x) {
            return __upper_bound(n->right, x);
        } else {
            Node *res = __upper_bound(n->left, x);
            return res ? res : n;
        }
    }
};

int main() {
    TreapArray<int> a;
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    while (q--) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x == 0) {
            int len = z - y + 1;
            Treap<int>::Node *l, *m1, *m2, *r;
            tie(l, r) = a.split(a.root, y);
            tie(m1, r) = a.split(r, len);
            tie(m1, m2) = a.split(m1, len - 1);
            m1 = a.merge(m2, m1);
            r = a.merge(m1, r);
            a.root = a.merge(l, r);
        } else if (x == 1) {
            int len = z - y + 1;
            Treap<int>::Node *l, *m, *r;
            tie(l, r) = a.split(a.root, y);
            tie(m, r) = a.split(r, len);
            cout << (m->data) << endl;
            r = a.merge(m, r);
            a.root = a.merge(l, r);
        } else {
            Treap<int>::Node *l, *m, *r;
            tie(l, r) = a.split(a.root, y);
            tie(m, r) = a.split(r, 1);
            m->val = z;
            r = a.merge(m, r);
            a.root = a.merge(l, r);
        }
    }
    return 0;
}