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;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MinMonoid {
  using T = int;
  static T op(const T& lhs, const T& rhs) { return min(lhs, rhs); }
  static constexpr T e() { return numeric_limits<T>::max(); }
};

template<class Monoid> struct RandomizedBinarySearchTree {
  using M = Monoid;
  using T = typename M::T;
  struct Node;
  using Tree = Node*;

  struct Node {
    T a = M::e();
    Tree cl = nullptr, cr = nullptr;
    int n = 1;
    T val = a;
  };

  static Tree merge(Tree tl, Tree tr) {
    if (!tr) return tl;
    if (!tl) return tr;
    if (rng(0, tl->n + tr->n) < tl->n) {
      tl->cr = merge(tl->cr, tr);
      return update(tl);
    } else {
      tr->cl = merge(tl, tr->cl);
      return update(tr);
    }
  }

  static pair<Tree, Tree> split(Tree t, int i) {
    if (!t) return {nullptr, nullptr};
    int nl = t->cl ? t->cl->n : 0;
    if (i <= nl) {
      Tree resl;
      tie(resl, t->cl) = split(t->cl, i);
      return {resl, update(t)};
    } else {
      Tree resr;
      tie(t->cr, resr) = split(t->cr, i - nl - 1);
      return {update(t), resr};
    }
  }

  static Tree insert(Tree t, int i, const T& a) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    return merge(merge(tl, new Node{a}), tr);
  }

  static Tree erase(Tree t, int i) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    tr = split(tr, 1).second;
    return merge(tl, tr);
  }

private:
  template<class Int> static Int rng(Int a, Int b) {
    static mt19937 mt(chrono::steady_clock().now().time_since_epoch().count());
    assert(a < b);
    return uniform_int_distribution<Int>(a, b - 1)(mt);
  }

  static Tree update(Tree t) {
    t->n = (t->cl ? t->cl->n : 0) + 1 + (t->cr ? t->cr->n : 0);
    t->val = M::op(M::op(t->cl ? t->cl->val : M::e(), t->a), t->cr ? t->cr->val : M::e());
    return t;
  }
};

using RBST = RandomizedBinarySearchTree<MinMonoid>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  RBST::Tree t = nullptr;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    t = RBST::insert(t, i, a);
  }
  for (int _ = 0; _ < q; ++_) {
    int type; cin >> type;
    if (type == 0) {
      int l, r; cin >> l >> r, ++r;
      RBST::Tree tl, tm, tr;
      tie(tm, tr) = RBST::split(t, r);
      tie(tl, tm) = RBST::split(tm, l);
      RBST::Tree tml, tmr;
      tie(tml, tmr) = RBST::split(tm, r - l - 1);
      tm = RBST::merge(tmr, tml);
      t = RBST::merge(RBST::merge(tl, tm), tr);
    } else if (type == 1) {
      int l, r; cin >> l >> r, ++r;
      RBST::Tree tl, tm, tr;
      tie(tm, tr) = RBST::split(t, r);
      tie(tl, tm) = RBST::split(tm, l);
      cout << tm->val << '\n';
      t = RBST::merge(RBST::merge(tl, tm), tr);
    } else {
      int i, a; cin >> i >> a;
      t = RBST::erase(t, i);
      t = RBST::insert(t, i, a);
    }
  }
}