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>
#ifdef CHECK_

class Node {
public:
  Node *left, *right;
  int num;
  int value;
  int min;
  Node() {}
};

Node *root;

Node* initLeaf(int v) {
  Node *res = new Node;
  res->left = res->right = nullptr;
  res->num = 1;
  res->value = v;
  res->min = v;
  return res;
}

Node* initNode(Node* left, Node* right) {
  Node *res = new Node;
  res->left = left;
  res->right = right;
  res->num = 0;
  res->value = 0;
  res->min = (1 << 30);
  return res;
}

bool isLeaf(Node* p) {
  if( p == nullptr ) return false;
  return p->left == nullptr and p->right == nullptr;
}


int getNum(Node* p) {
  if( p == nullptr ) return 0;
  if( isLeaf(p) ) return 1;
  return p->num;
}

Node* getLeft(Node* p) {
  if( p == nullptr ) return nullptr;
  return p->left;
}

Node* getRight(Node* p) {
  if( p == nullptr ) return nullptr;
  return p->right;
}

int getValue(Node* p) {
  if( p == nullptr ) return (1 << 30);
  //assert( p != nullptr );
  return p->value;
}


// checker
void dump2(Node* node) {
  if( node == nullptr ) return;
  if( node->left == nullptr and node->right == nullptr ) {
    printf("{%d,%d}", node->value, node->min);
    return;
  }
  printf("(%d,%d)[", node->num, node->min);
  dump2(node->left);
  putchar(',');
  dump2(node->right);
  putchar(']');
}

Node* dump(Node* node) {
  dump2(node);
  putchar('\n');
  return node;
}

int maxDepth(Node* node) {
  if( node == nullptr ) return -1;
  if( isLeaf(node) ) return 0;
  return 1 + std::max(maxDepth(getLeft(node)), maxDepth(getRight(node)));
} 


Node* update(Node* p) {
  if( p == nullptr ) return nullptr;
  assert( not isLeaf(p) );
  p->num = getNum(getLeft(p)) + getNum(getRight(p));
  if( isLeaf(p) ) {
    p->min = p->value;
  }
  else {
    p->min = std::min(getValue(getLeft(p)), getValue(getRight(p)));
  }
  return p;
}

Node* merge(Node* left, Node* right) {
  if( left == nullptr and right == nullptr ) return nullptr;
  if( isLeaf(left) and isLeaf(right) ) return update(initNode(left, right));
  if( left == nullptr and isLeaf(right) ) return right;
  if( right == nullptr and isLeaf(left) ) return left;
  if( left == nullptr or right == nullptr ) return update(initNode(left, right));
  if( getNum(left) < getNum(right) or (getNum(left) == getNum(right) and rand() % 2 == 0) ) {
    if( isLeaf(right) ) return update(initNode(left, right));
    // left merged
    Node *w = merge(left, getLeft(right));
    Node *v = initNode(w, getRight(right));
    assert( not isLeaf(v) );
    if( isLeaf(w) ) return update(v);
    //rotate right only
    //right
    if( getNum(getLeft(w)) > getNum(getRight(v)) ) {
      v->left  = getRight(w);
      w->right = v;
      update(v);
      return update(w);
    }
    if( not isLeaf(getRight(w)) and std::abs(getNum(w) - getNum(getRight(v))) > std::abs((getNum(getLeft(w)) + getNum(getLeft(getRight(w)))) - (getNum(getRight(getRight(w))) + getNum(getRight(v)))) ) {
      Node *x = initNode(w, v);
      v->left  = getRight(getRight(w));
      w->right = getLeft(getRight(w));
      update(w);
      update(v);
      return update(x);
    }
    return update(v);
  }
  else {
    if( isLeaf(left) ) return update(initNode(left, right));
    Node *w = merge(getRight(left), right);
    Node *v = initNode(getLeft(left), w);
    assert( not isLeaf(v) );
    if( isLeaf(w) ) return update(v);
    // rotate left only
    // left
    if( getNum(getLeft(v)) < getNum(getRight(w)) ) {
      v->right = getLeft(w);
      w->left  = v;
      update(v);
      return update(w);
    }
    if( not isLeaf(getLeft(w)) and std::abs(getNum(getLeft(v)) - getNum(w)) > std::abs((getNum(getLeft(v)) + getNum(getLeft(getLeft(w)))) - (getNum(getRight(getLeft(w))) + getNum(getRight(w)))) ) {
      Node *x = initNode(v, w);
      v->right = getLeft(getLeft(w));
      w->left  = getRight(getLeft(w));
      update(v);
      update(w);
      return update(x);
    }
    return update(v);
  }
}

// [0, k), [k, size)
std::pair<Node*, Node*> split(Node* p, int k) {
  if( getNum(p) == k ) return std::pair<Node*, Node*>(p, nullptr);
  if( k == 0 ) return std::pair<Node*, Node*>(nullptr, p);
  if( k <= getNum(getLeft(p)) ) {
    Node *left, *right;
    std::tie(left, right) = split(getLeft(p), k);
    return std::pair<Node*, Node*>(left, merge(right, getRight(p)));
  }
  else {
    Node *left, *right;
    std::tie(left, right) = split(getRight(p), k - getNum(getLeft(p)));
    return std::pair<Node*, Node*>(merge(getLeft(p), left), right);
  }
}

// [l, r)
int minimum(Node* p, int l, int r) {
  if( isLeaf(p) ) return p->value;
  //if( l == 0 and r == getNum(p) ) return p->min;
  if( r <= getNum(getLeft(p)) ) {
    return minimum(getLeft(p), l, r);
  }
  else if( getNum(getLeft(p)) <= l ) {
    return minimum(getRight(p), l - getNum(getLeft(p)), r - getNum(getLeft(p)));
  }
  else {
    int leftmin  = minimum(getLeft(p), l, getNum(getLeft(p)));
    int rightmin = minimum(getRight(p), 0, r - getNum(getLeft(p)));
    return std::min(leftmin, rightmin);
  }
}


int main() {
  Node *root = nullptr;
  int n = get<int>();
  int q = get<int>();
  for(int i = 0; i < n; ++i) {
    int a = get<int>();
    root = merge(root, initLeaf(a));
    //dump(root);
  }
  for(int i = 0; i < q; ++i) {
    const int x = get<int>();
    int y = get<int>();
    int z = get<int>();
    if( x == 0 ) {
      Node *nl, *nr;
      std::tie(nl, nr) = split(root, z + 1);
      Node *nll, *nlr;
      std::tie(nll, nlr) = split(nl, z);
      Node *nlll, *nllr;
      std::tie(nlll, nllr) = split(nll, y);
      root = merge(merge(merge(nlll, nlr), nllr), nr);      
    }
    if( x == 1 ) {
      int res = minimum(root, y, z + 1);
      printf("%d\n", res);
    }
    if( x == 2 ) {
      Node *nl, *nr;
      std::tie(nl, nr) = split(root, y + 1);
      Node *nll, *nlr;
      std::tie(nll, nlr) = split(nl, y);
      root = merge(merge(nll, initLeaf(z)), nr);
    }
    //dump(root);
  }
  // int t = getNum(root);
  // root = merge(root, root);
  // dump(root);
  // root = split(root, t).first;
  // dump(root);
  // for(int i = 0; i < 17; ++i) {
  //   root = merge(root, root);
  // }
  // printf("numnode  : %d\n", getNum(root));
  // printf("maxdepth : %d\n", maxDepth(root));
  
  return 0;
}

#else

template<typename T>
T get() { return 0; }
template<>
int get() { int x; scanf("%d", &x); return x; }
template<>
long get() { long x; scanf("%ld", &x); return x; }

template<typename T>
void put(T x) {}
template<>
void put(int x) { printf("%d\n", x); }
template<>
void put(long x) { printf("%ld\n", x); }
template<>
void put(std::string str) { printf("%s\n", str.c_str()); }
template<>
void put(const char* str) { printf("%s\n", str); }

#define CHECK_
#include __FILE__
#endif