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>

template<typename T>
class treap_seq{
    using value_type = T;
    using size_type = size_t;

    class node_t {
    public:
        value_type value, query;
        size_type priority, size;
        node_t *left, *right;

        constexpr node_t(value_type _value, size_type _priority) : value(_value), query(_value), priority(_priority), size(1), left(
                nullptr), right(nullptr) {}

        constexpr value_type operator*() noexcept { return value; }

        constexpr size_type get_priority() noexcept { return priority; }

        constexpr value_type operator[](size_type k) {
            auto t = left ? left -> size : 0;
            return t < k ? (*right)[k - t - 1] : (t > k ? (*left)[k] : this -> value);
        }

        constexpr node_t *lower_bound(value_type v) {
            if (value == v)return this;
            if (value < v) {
                if (!left)return left;
                return left->lower_bound(v);
            } else {
                if (!right)return this;
                return right->lower_bound(v);
            }
        }

        constexpr size_t lower_size(value_type v) {
            if(value == v)return left ? left -> size : 0;
            if(value < v)return (left ? left -> size : 0) + 1 + (right ? right -> lower_size(v) : 0);
            return (left ? left -> lower_size(v) : 0);
        }

        void print(size_t n, std::ostream& os){
            if(right)right -> print(n + 5, os);
            for(size_t i = 0; i < n; ++i)os << " ";
            os << "(" << value << ", " << query << ", " << (priority >> 32) << ")" << std::endl;
            if(left)left -> print(n + 5, os);
        }
    };

    node_t* root;

    node_t* update(node_t* node){
        node -> size = 1;
        node -> query = node -> value;
        if(node -> left){
            node -> size += node -> left -> size;
            node -> query = std::min(node -> query, node -> left -> query);
        }
        if(node -> right){
            node -> size += node -> right -> size;
            node -> query = std::min(node -> query, node -> right -> query);
        }
        return node;
    }

    size_t sze(node_t* node) {
        return node ? node -> size : 0;
    }

    node_t* merge(node_t* left, node_t* right){
        /*if(left)left -> print(0);
        else puts("v");
        if(right)right -> print(0);
        else puts("v");
        puts("");*/
        if(!left)return right;
        if(!right)return left;

        if(left -> get_priority() > right -> get_priority()){
            left -> right = merge(left -> right, right);
            return update(left);
        }else{
            right -> left = merge(left, right -> left);
            return update(right);
        }
    }

    std::pair<node_t*, node_t*> split(node_t* root, size_t nth){
        if(!root)return {nullptr, nullptr};

        if(nth <= sze(root -> left)){
            auto s = split(root -> left, nth);
            root -> left = s.second;
            return {s.first, update(root)};
        }else{
            auto s = split(root -> right, nth - 1 - sze(root -> left));
            root -> right = s.first;
            return {update(root), s.second};
        }
    }

public:

    explicit treap_seq(value_type _v, size_type _p) : root(new node_t(_v, _p)) {}

    treap_seq() : root(nullptr) {}

    void insert(T value, size_t priority, size_type ichi){
        if(root){
            auto *nw = new node_t(value, priority);
            auto t = split(root, ichi);
            root = merge(merge(t.first, nw), t.second);
        }else{
            root = new node_t(value, priority);
        }
    }

    void erase(/*value_type value, */size_type k){
        //auto k = root -> lower_size(value);
        auto t1 = split(root, k);
        auto t2 = split(t1.second, 1);
        root = merge(t1.first, t2.second);
    }

    void shift(size_type l, size_type r){
        auto t = split(root, r);
        auto k = split(t.first, r - 1);
        auto s = split(k.first, l);
        root = merge(merge(s.first, k.second), merge(s.second, t.second));
    }

    value_type query(size_type l, size_type r){
        auto t1 = split(root, r);
        auto t2 = split(t1.first, l);
        auto ret = t2.second -> query;
        root = merge(merge(t2.first, t2.second), t1.second);
        return ret;
    }

    constexpr value_type operator[](size_type k) {
        return (*root)[k];
    }

    void print(std::ostream& os = std::cout){
        if(root)root -> print(0, os);
    }
};

int main(){
    using namespace std;
    size_t n, q;
    cin >> n >> q;
    random_device rdv{};
    mt19937_64 mt(rdv());
    treap_seq<size_t> tp;
    for(unsigned long i = 0, a; i < n; ++i){
        cin >> a;
        tp.insert(a, mt(), i);
    }
    //tp.print(cerr);
    for(unsigned long i = 0, x, y, z; i < q; ++i){
        cin >> x >> y >> z;
        if(x == 0){
            tp.shift(y, z + 1);
        }else if(x == 1){
            cout << tp.query(y, z + 1) << endl;
        }else{
            tp.erase(y);
            tp.insert(z, mt(), y);
        }
    }
    return 0;
}