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

using Key = int;
const Key INF = 1e9;
const int MAX_N = 1000010;  // ?????\??????????° + EPS

struct node {
    Key key;
    node *left, *right;
    int size;
    Key min;

    static node *const NIL;

    node() {}

    node(const Key &x) : node(x, NIL, NIL, 1, x) {}

    node(const Key &key_, node *left_, node *right_, int size_, const Key &min_)
        : key(key_), left(left_), right(right_), size(size_), min(min_) {}

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

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

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

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

bool is_leaf(cnp n){
    return n->left == node::NIL;
}

class treap {
public:
    np root;


    treap() : root(node::NIL) {}

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

    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2099535#1
    treap(Key *left, Key *right) : root(__make_tree(left, right)) { }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2099535#1
    np __make_tree(Key *left, Key *right) {
        int sz = right - left;
        Key *mid = left + sz / 2;
        if (sz == 0){
            return node::NIL;
        } else if (sz == 1) {
            return new node(*mid, node::NIL, node::NIL, 1, *mid);
        } else {
            np lc = __make_tree(left, mid);
            np rc = __make_tree(mid, right);
            return new node(-1, lc, rc, sz, std::min(lc->min, rc->min));
        }
    }


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


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void set(int k, const Key &x) { __set(root, k, x); }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void __set(np n, int k, const Key &x) {
        if (n->size == 1) {
            n->key = n->min = x;
        } else {
            if (k < n->left->size)
                __set(n->left, k, x);
            else
                __set(n->right, k - n->left->size, x);
            __update(n);
        }
    }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key get(int k) const { return __get(root, k); }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key __get(np n, int k) const {
        if (n->size == 1) {
            return n->key;
        } else if (k < n->left->size)
            return __get(n->left, k);
        else
            return __get(n->right, k - n->left->size);
    }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key range_min(int l, int r) { return __range_min(root, l, r); }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key __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){
            // dump(l);
            // dump(r);
            // dump(n->size);
            // dump(n->min);
            return n->min;
        }
        Key res = INF;
        int sl = n->left->size;
        res = std::min(res, __range_min(n->left, l, r));
        res = std::min(res, __range_min(n->right, l - sl, r - sl));
        return res;
    }


    void merge_from_left(treap &t) { root = __merge(t.root, root); }

    void merge_from_right(treap &t) { root = __merge(root, t.root); }

    np __merge_sub(np l, np r) const {
        int sl = l->size, sr = r->size;
        int rand = node::xor128() % (sl + sr + 1);
        if (rand < sl){
            if(is_leaf(l)) return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
            l->right = __merge_sub(l->right, r);
            return __update(l);
        } else if(rand == sl) {
            return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
        } else {
            if(is_leaf(r)) return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
            r->left = __merge_sub(l, r->left);
            return __update(r);
        }
    }

    np __merge(np l, np r) const {
        if(l == node::NIL) return r;
        if(r == node::NIL) return l;
        return __merge_sub(l, r);
    }

    std::pair<treap, treap> split_at(int k) {
        np l, r;
        std::tie(l, r) = __split_at(root, k);
        return std::make_pair(treap(l), treap(r));
    }

    npair __split_at(np n, int k) const {
        if(n == node::NIL) return npair(node::NIL, node::NIL);
        else return __split_at_sub(n, k);
    }

    npair __split_at_sub(np n, int k) const {
        if (is_leaf(n)) {
            return k == 0 ? npair(node::NIL, n) : npair(n, node::NIL);
        } else if (k < n->left->size) {
            npair p = __split_at_sub(n->left, k);
            n->left = p.second;
            return npair(p.first, __update(n));
        } else if (k == n->left->size) {
            return npair(n->left, n->right);
        } else {
            npair p = __split_at_sub(n->right, k - n->left->size);
            n->right = p.first;
            return npair(__update(n), p.second);
        }
    }

    // np __update(np n) const {
    //     // assert(n->left != node::NIL);
    //     n->size = n->left->size + n->right->size + (n->left == node::NIL);
    //     n->min = std::min({ n->left->min, n->right->min, (n->left == node::NIL ? n->key : INF)});
    //     return n;
    // }
    np __update(np n) const {
        // assert(n->left != node::NIL);
        n->size = n->left->size + n->right->size;
        n->min = std::min(n->left->min, n->right->min);
        return n;
    }

    void shift(int l, int r) {
        //std::cout << "shift " << l << ' ' << r << std::endl;
        np a, b, c, d;
        std::tie(a, b) = __split_at(root, l);
        std::tie(b, c) = __split_at(b, r - l);
        std::tie(c, d) = __split_at(c, 1);
        np ac = __merge(a, c);
        np bd = __merge(b, d);
        root = __merge(ac, bd);
    }
};

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)

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];
    treap t(a, a + n);

    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x == 0) {
            t.shift(y, z);
        }
        if (x == 1) {
            cout << t.range_min(y, z + 1) << '\n';
        }
        if (x == 2) {
            t.set(y, z);
        }
    }
}