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 <algorithm>
#include <cassert>
#include <ctime>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#define dump(x) std::cerr << __LINE__ << ":\t" #x " = " << x << std::endl

int32_t xor128() {
    static uint32_t x = 123456789, y = 362436069, z = 521288629, w = time(0);
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w & 0x3FFFFFFF;
}

using key_t = int;
const key_t INF = 1000000000;
const int MAX_N = 5000010;
enum { L, R };
struct node {
    key_t key;
    node *ch[2];
    int size;
    key_t min;

    static node *const nil;

    node() : node(0) {}

    node(const key_t &x) : key(x), size(1), min(x) {
        ch[L] = node::nil;
        ch[R] = node::nil;
    }

    node(node *left_, node *right_, int size_, const key_t &min_)
        : size(size_), min(min_) {
        ch[L] = left_;
        ch[R] = right_;
    }

    void *operator new(std::size_t) {
        static node pool[MAX_N];
        static int p = 0;
        return pool + p++;
    }

    bool is_leaf() const { return size == 1; }
};

using np = node *;
using cnp = const node *;
using npair = std::pair<np, np>;

node *const node::nil = new node(nullptr, nullptr, 0, INF);

struct rbst {
    np root;

    rbst() : root(node::nil) {}

    rbst(np root_) : root(root_) {}

    rbst(key_t *left, key_t *right) : root(make_tree(left, right)) {}

    np make_tree(key_t *left, key_t *right) {
        int sz = right - left;
        key_t *mid = left + sz / 2;
        if (sz == 0) {
            return node::nil;
        } else {
            np par = new node(*mid);
            par->ch[L] = make_tree(left, mid);
            par->ch[R] = make_tree(mid+1, right);
            return update(par);
        }
    }

    int size() const { return root->size; }

    void set(int k, const key_t &x) { set(root, k, x); }

    void set(np n, int k, const key_t &x) {
        if (k < n->ch[L]->size)
            set(n->ch[L], k, x);
        else if (n->ch[L]->size == k)
            n->key = x;
        else {
            set(n->ch[R], k - n->ch[L]->size - 1, x);
        }
        update(n);
    }

    key_t get(cnp n, int k) const {
        if (k < n->ch[L]->size)
            return get(n->ch[L], k);
        else if (n->ch[L]->size == k)
            return n->key;
        else
            return get(n->ch[R], k - n->ch[L]->size - 1);
    }

    key_t range_min(int l, int r) const { return range_min(root, l, r); }

    key_t range_min(cnp n, int l, int r) const {
        l = std::max(l, 0);
        r = std::min(r, n->size);
        if (l >= r) return INF;
        if (l == 0 && r == n->size) return n->min;
        key_t res = INF;
        int sl = n->ch[0]->size;
        res = std::min(res, range_min(n->ch[0], l, r));
        res = std::min(res, range_min(n->ch[1], l - sl - 1, r - sl - 1));
        if (l <= sl && sl < r) res = std::min(res, n->key);
        return res;
    }

    np merge(np l, np r) const {
        if (l == node::nil) return r;
        if (r == node::nil) return l;
        int sl = l->size, sr = r->size;
        if (xor128() % (sl + sr) < sl) {
            l->ch[R] = merge(l->ch[R], r);
            return update(l);
        } else {
            r->ch[L] = merge(l, r->ch[L]);
            return update(r);
        }
    }

    npair split(np n, int k) const {
        if (n == node::nil) return {node::nil, node::nil};
        if (k <= n->ch[L]->size) {
            npair p = split(n->ch[L], k);
            n->ch[L] = p.second;
            return npair(p.first, update(n));
        } else {
            npair p = split(n->ch[R], k - n->ch[L]->size - 1);
            n->ch[R] = p.first;
            return npair(update(n), p.second);
        }
    }

    np insert(np n, int k, const key_t &x) const {
        if (n == node::nil) return new node(x);
        if (k <= n->ch[L]->size) n->ch[L] = insert(n->ch[L], k, x);
        else n->ch[R] = insert(n->ch[R], k - n->ch[L]->size - 1, x);
        n = update(n);
        int sl = n->ch[L]->size, sr = n->ch[R]->size;
        int rand = xor128() % (sl + sr);
        return rand < sl ? rotate<R>(n) : rotate<L>(n);
    }

    np erase(np n, int k) const {
        assert(n != node::nil);
        if (n == node::nil) return node::nil;
        if (k < n->ch[L]->size) n->ch[L] = erase(n->ch[L], k);
        else if(k == n->ch[L]->size) return erase(n);
        else n->ch[R] = erase(n->ch[R], k - n->ch[L]->size - 1);
        return update(n);
    }

    np erase(np n) const {
        assert(n != node::nil);
        if(n->ch[L] == node::nil) return n->ch[R];
        if(n->ch[R] == node::nil) return n->ch[L];
        int sl = n->ch[L]->size, sr = n->ch[R]->size;
        int rand = xor128() % (sl + sr);
        if(rand < sl) {
            n = rotate<R>(n);
            n->ch[R] = erase(n->ch[R]);
        } else {
            n = rotate<L>(n);
            n->ch[L] = erase(n->ch[L]);
        }
        return update(n);
    }

    template <int dir> np rotate(np n) const {
        np par = n->ch[1 - dir];
        n->ch[1 - dir] = par->ch[dir];
        par->ch[dir] = update(n);
        return update(par);
    }

    np update(np n) const {
        n->size = n->ch[L]->size + n->ch[R]->size + 1;
        n->min = std::min({n->ch[L]->min, n->ch[R]->min, n->key});
        return n;
    }

    void shift_split_merge(int l, int r) {
        np a, b, c, d;
        std::tie(a, b) = split(root, l);
        std::tie(b, c) = split(b, r - l);
        std::tie(c, d) = split(c, 1);
        np ac = merge(a, c);
        np bd = merge(b, d);
        root = merge(ac, bd);
    }

    void shift_erase_insert(int l, int r) {
        key_t x = get(root, r);
        root = erase(root, r);
        root = insert(root, l, x);
    }
};

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    static int a[200010];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    rbst t(a, a + n);
    rbst u(a, a + n);

    // u.show_array();

    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x == 0) {
            t.shift_split_merge(y, z);
            u.shift_erase_insert(y, z);
            // u.show_array();
        }
        if (x == 1) {
            int a = t.range_min(y, z + 1);
            int b = u.range_min(y, z + 1);
            if (a != b) throw 0;
            cout << a << '\n';
        }
        if (x == 2) {
            t.set(y, z);
            u.set(y, z);
        }
    }
}