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 <utility>
#include <cassert>
#include <set>
using namespace std;

template<class T>
struct splay_array {
  struct node {
    node* left;
    node* right;
    node* parent;
    T val;
    T rmq;
    size_t size;
    node(T v) : val(v),rmq(v), left(nullptr), right(nullptr), parent(nullptr){}
    ~node() {
      delete left , left = nullptr;
      delete right , right = nullptr;
    }
  };
private:
  size_t subtree_size(node* x) {
    if(x) return x->size;
    return 0;
  }
  T rmq(node* x) {
    if(!x) return 1e9;
    return x->rmq;
  }
  node* fix(node* n) {
    if(!n) return nullptr;
    n->size = subtree_size(n->left) + subtree_size(n->right) + 1;
    n->rmq = std::min(std::min(rmq(n->left), n->val), rmq(n->right));
    return n;
  }
  void setl(node* par, node* x) {
    if(par) par->left = x;
    if(x) x->parent = par;
    fix(par);
  }
  void setr(node* par, node* x) {
    if(par) par->right = x;
    if(x) x->parent = par;
    fix(par);
  }
  void zig(node* x) {
    node* p = x->parent;
    setl(p, x->right);
    if(p->parent) {
      if(p->parent->left == p) setl(p->parent, x);
      else setr(p->parent, x);
    }
    else x->parent = nullptr;
    setr(x, p);
  }
  void zag(node* x) {
    node* p = x->parent;
    setr(p, x->left);
    if(p->parent) {
      if(p->parent->left == p) setl(p->parent, x);
      else setr(p->parent, x);
    }
    else x->parent = nullptr;
    setl(x, p);
  }
  node* splay(node* x) {
    if(!x) return nullptr;
    while(x->parent) {
      if(!x->parent->parent){
        if(x->parent->left == x) zig(x);
        else zag(x);
      }
      else if(x->parent->parent->left == x->parent && x->parent->left == x){
        zig(x->parent);
        zig(x);
      }
      else if(x->parent->parent->left == x->parent && x->parent->right == x){
        zag(x);
        zig(x);
      }
      else if(x->parent->parent->right == x->parent && x->parent->right == x){
        zag(x->parent);
        zag(x);
      }
      else{
        zig(x);
        zag(x);
      }
    }
    return x;
  }

  node* find(node* r, size_t i) {
    assert(0 <= i);
    assert(i < subtree_size(r));
    node* z = r;
    while(z){
      if(subtree_size(z->left) == i){
        return splay(z);
      }
      else if(subtree_size(z->left) < i){
        i -= subtree_size(z->left) + 1;
        z = z->right;
      }
      else{
        z = z->left;
      }
    }
    assert(false);
  }

  pair<node*,node*> split(node* r, size_t i) {
    assert(0 <= i);
    assert(i <= subtree_size(r));
    if(i == 0) return {nullptr, r};
    if(i == subtree_size(r)) return {r, nullptr};
    r = find(r, i - 1);
    node* y = r->right;
    if(y) y->parent = nullptr;
    r->right = nullptr;
    fix(r);
    return {r, y};
  }

  node* merge(node* r1, node* r2) {
    if(!r1) {
      r1 = r2;
    }
    else if(!r2) {
    }
    else {
      size_t sz = subtree_size(r1);
      r1 = find(r1, sz - 1);
      setr(r1,r2);
    }
    return r1;
  }

  node* root;
public:
  using sarr = splay_array<T>;
  splay_array() : root(nullptr) {}
  splay_array(node* r) : root(r) {}
  splay_array(splay_array&& arr) {
    root = arr.root;
    arr.root = nullptr;
  }
  splay_array& operator=(splay_array&& arr) {
    root = arr.root;
    arr.root = nullptr;
    return *this;
  }
  ~splay_array() { delete root; }
  pair<sarr,sarr> split(size_t i) {
    pair<node*,node*> p = split(root, i);
    root = nullptr;
    return {sarr(p.first), sarr(p.second)};
  }
  void merge(sarr&& arr) {
    root = merge(root, arr.root);
    arr.root = nullptr;
  }
  void insert(size_t i, T val) {
    node* x = new node(val);
    auto p = split(root, i);
    setl(x, p.first);
    setr(x,p.second);
    root = x;
  }
  void erase(size_t i) {
    auto p = split(root, i + 1);
    auto q = split(p.first, i);
    fix(q.first);
    fix(p.second);
    if(p.first) {
      p.first->left = nullptr;
      p.first->right = nullptr;
      delete p.first, p.first = nullptr;
    }
    root = merge(q.first, p.second);
    fix(root);
  }
  T at(size_t i) {
    return (root = find(root,i))->val;
  }
  void set(size_t i, T t) {
    (root = find(root,i))->val = t;
    fix(root);
  }
  size_t size() {
    return subtree_size(root);
  }
  T min() {
    return rmq(root);
  }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int n,q;
  cin >> n >> q;
  splay_array<int> arr;
  for(int i = 0;i < n;i++) {
    int x;
    cin >> x;
    arr.insert(i,x);
  }
  for(int i = 0;i < q;i++) {
    int x,y,z;
    cin >> x >> y >> z;
    if(x == 0) {
      int l = y;
      int r = z;
      //[0,l - 1] [l, r - 1] [r] [r + 1]
      //[0,l - 1] [r] [l, r - 1] [r + 1]
      auto p = arr.split(r + 1);
      auto q = p.first.split(r);
      auto rr = q.first.split(l);
      rr.first.merge(move(q.second));
      rr.first.merge(move(rr.second));
      rr.first.merge(move(p.second));
      arr = move(rr.first);
    }
    if(x == 1) {
      int l = y;
      int r = z;
      auto p = arr.split(r + 1);
      auto q = p.first.split(l);
      cout << q.second.min() << endl;
      q.first.merge(move(q.second));
      q.first.merge(move(p.second));
      arr = move(q.first);
    }
    if(x == 2) {
      int pos = y;
      int val = z;
      arr.set(pos,val);
    }
  }
}