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<ctime>
using namespace std;

// merge-split ベース

#include<vector>
#include<algorithm>
#include<memory>
#include<cstdlib>
#include<climits>

class Treap {
public:
    int size();
    void insert(const int index, const int value);
    void erase(const int index);
    void circular_shift(const int left, const int right);
    int find(const int index) const;
    int min(const int left, const int right) const;
    int sum(const int left, const int right) const;

private:
    static const int INF = INT_MAX;     // for min()
    struct Node;

    int size(const std::unique_ptr<Node>& node) const;
    int sum(const std::unique_ptr<Node>& node) const;
    int min(const std::unique_ptr<Node>& node) const;
    int find(const std::unique_ptr<Node>& node, const int index) const;
    std::unique_ptr<Node> update(std::unique_ptr<Node>& node);
    std::unique_ptr<Node> merge(std::unique_ptr<Node>& left, std::unique_ptr<Node>& right);
    std::vector<std::unique_ptr<Node>> split(std::unique_ptr<Node>& node, const int k);
    int sum(const std::unique_ptr<Node>& node, const int left, const int right) const;
    int min(const std::unique_ptr<Node>& node, const int left, const int right) const;

    std::unique_ptr<Node> root_;
};

// struct
struct Treap::Node {
    int value;
    int sum;
    int min;
    int size;
    double priority;
    std::unique_ptr<Node> left_child, right_child;
    Node(int v) :value(v), sum(v), min(v), size(1), priority(std::rand()), left_child(nullptr), right_child(nullptr) {}
};

// public
int Treap::size() {return size(root_);}
void Treap::insert(const int index, const int value) {
    auto t = split(root_, index);
    std::unique_ptr<Node> n(new Node(value));
    root_ = merge(t[0], n);
    root_ = merge(root_, t[1]);
}
void Treap::erase(const int index) {
    auto t1 = split(root_, index);
    auto t2 = split(t1[1], 1);
    root_ = merge(t1[0], t2[1]);
}
void Treap::circular_shift(const int left, const int right) {
    auto t1 = split(root_, right + 1);
    auto t2 = split(t1[0], right);
    auto t3 = split(t2[0], left);
    root_ = merge(t3[0], t2[1]);
    root_ = merge(root_, t3[1]);
    root_ = merge(root_, t1[1]);
}
int Treap::find(const int index) const {return find(root_, index);}
int Treap::min(const int left, const int right) const {return min(root_, left, right);}
int Treap::sum(const int left, const int right) const {return sum(root_, left, right);}

// private
int Treap::size(const std::unique_ptr<Node>& node) const {return node ? node->size : 0;}
int Treap::sum(const std::unique_ptr<Node>& node) const {return node ? node->sum : 0;}
int Treap::min(const std::unique_ptr<Node>& node) const {return node ? node->min : INF;}
int Treap::find(const std::unique_ptr<Node>& node, const int index) const {
    if(index < size(node->left_child))         return find(node->left_child, index);
    else if(index == size(node->left_child))    return node->value;
    else                                        return find(node->right_child, index - size(node->left_child) - 1);
}
std::unique_ptr<Treap::Node> Treap::update(std::unique_ptr<Node>& node) {
    node->size = size(node->left_child) + size(node->right_child) + 1;
    node->sum = sum(node->left_child) + sum(node->right_child) + node->value;
    node->min = std::min({min(node->left_child), min(node->right_child), node->value});
    return std::move(node);
}
std::unique_ptr<Treap::Node> Treap::merge(std::unique_ptr<Node>& left, std::unique_ptr<Node>& right) {
    if(!left || !right) return std::move(left ? left : right);
    if(left->priority > right->priority) {
        left->right_child = merge(left->right_child, right);
        return update(left);
    } else {
        right->left_child = merge(left, right->left_child);
        return update(right);
    }
}
std::vector<std::unique_ptr<Treap::Node>> Treap::split(std::unique_ptr<Node>& node, const int k) {
    std::vector<std::unique_ptr<Node>> result(2);
    if(!node) return result;
    if(k <= size(node->left_child)) {
        result = split(node->left_child, k);
        node->left_child = std::move(result[1]);
        result[1] = update(node);
    } else {
        result = split(node->right_child, k - size(node->left_child) - 1);
        node->right_child = std::move(result[0]);
        result[0] = update(node);
    }
    return result;
}
int Treap::sum(const std::unique_ptr<Node>& node, const int left, const int right) const {
    if(!node) return 0;
    if(right < 0 || size(node) < left) return 0;
    if(left <= 0 && size(node) <= right) return node->sum;
    int result = sum(node->left_child, left, right) + sum(node->right_child, left - size(node->left_child) - 1, right - size(node->left_child) - 1);
    if(left <= size(node->left_child) && size(node->left_child) <= right) return result + node->value;
    return result;
}
int Treap::min(const std::unique_ptr<Node>& node, const int left, const int right) const {
    if(!node) return INF;
    if(right < 0 || size(node) < left) return INF;
    if(left <= 0 && size(node) <= right) return node->min;
    int result = std::min(min(node->left_child, left, right), min(node->right_child, left - size(node->left_child) - 1, right - size(node->left_child) - 1));
    if(left <= size(node->left_child) && size(node->left_child) <= right) return std::min(result, node->value);
    return result;
}

int main() {
    int n, q;
    Treap rmq;
    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        rmq.insert(i, a);
    }
    for(int i = 0; i < q; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        if(x == 0) {
            rmq.circular_shift(y, z);
        } else if(x == 1) {
            cout << rmq.min(y, z) << endl;
        } else {
            rmq.erase(y);
            rmq.insert(y, z);
        }
    }
}