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<vector>
#include<algorithm>
#define INF (1<<29)

using namespace std;

const bool RED=false,BLACK=true;

struct RedBlackTree{
private:
  struct node_t{
    node_t *lch, *rch;
    bool color;
    int rank,size,val,mini;

    node_t(){
      lch=rch=NULL;
      color=BLACK;
      val=mini=INF;
      rank=0,size=1;
    }

    node_t(int val):val(val){
      mini=INF;
      lch=rch=NULL;
      rank=0;
      size=1;
    }

    node_t(int val, bool col)
      :color(col),val(val),mini(val){
      lch=rch=NULL;
      rank=0;
      size=1;
    }

    node_t(node_t *lch,node_t *rch,bool col)
      :lch(lch),rch(rch),color(col){
      val=mini=INF;
      size=0;
    }

    bool isLeaf(){return !lch && !rch;}
  };

  node_t *root;

  inline node_t *node(int val){
    return update(new node_t(val));
  }

  inline node_t *node(int val,bool color){
    return update(new node_t(val,color));
  }

  inline node_t *node(node_t *l,node_t *r,bool col){
    return update(new node_t(l,r,col));
  }

  inline bool color(node_t *t){return !t?RED:t->color;}
  inline int size(node_t *t){return !t?0:t->size;}
  inline int mini(node_t *t){return !t?INF:t->mini;}
  inline int rank(node_t *t){return !t?0:t->rank;}

  inline node_t *update(node_t *t){
    if(!t)return t;
    t->size=size(t->lch)+size(t->rch)+t->isLeaf();
    t->mini=min(min(mini(t->lch),mini(t->rch)),t->val);
    t->rank=rank(t->rch)+color(t->rch);
    return t;
  }

  node_t *mergeSub(node_t *l,node_t *r){
    
    l=update(l),r=update(r);

    if(l->rank < r->rank){
      node_t *c=mergeSub(l,r->lch);
      if(r->color==BLACK && c->color==RED && c->lch->color==RED){
	if(r->rch->color==BLACK){
	  return node(c->lch,node(c->rch,r->rch,RED),BLACK);
	} else {
	  //node_t *lch=node(c->lch,c->rch,BLACK);
	  //node_t *rch=node(r->rch->lch,r->rch->rch,BLACK);	  
	  node_t *lch=node(c->lch->lch,c->lch->rch,BLACK);
	  node_t *rch=node(c->rch,r->rch,BLACK);
	  return node(lch,rch,RED);
	}
      } 
      return node(c,r->rch,RED);
    }
    else if(l->rank > r->rank){
      node_t *c=mergeSub(l->rch,r);
      if(l->color==BLACK && c->color==RED && c->rch->color==RED){
	if(l->lch->color==BLACK){
	  return node(node(l->lch,c->lch,RED),c->rch,BLACK);
	} else {
	  //node_t *lch=node(l->lch->lch,l->lch->rch,BLACK);
	  //node_t *rch=node(c->lch,c->rch,BLACK);
	  node_t *lch=node(l->lch,c->lch,BLACK);
	  node_t *rch=node(c->rch->lch,c->rch->rch,BLACK);
	  return node(lch,rch,RED);
	}
      }
      return node(l->lch,c,RED);
    } 
    return node(l,r,RED);
  }
  
  node_t *insert(node_t *t,int k,int val){
    pair<node_t *,node_t *>s=split(t,k);
    node_t *tmp=node(val);
    t=merge(s.first,tmp);
    t=merge(t,s.second);
    return update(t);
  }
  
  node_t *erase(node_t *t,int k){
    pair<node_t *,node_t *>s1,s2;
    s2=split(t,k);
    s1=split(s2.first,k-1);
    delete s1.second;
    return update((t=merge(s1.first,s2.second)));
  }
  
  node_t *find(node_t *t, int k){
    pair<node_t *,node_t *>s1,s2;
    s2=split(t,k+1);
    s1=split(s2.first,k);
    node_t *res=s1.second;
    t=update((t=merge(s1.first,s1.second)));
    t=update((t=merge(t,s2.second)));
    return res;
    
  }
 
public:
  
  RedBlackTree():root(NULL){}
  
  node_t *merge(node_t *l,node_t *r){
    l=update(l),r=update(r);
    if(!l || !r)return l?l:r;
    node_t *c=mergeSub(l,r);
    if(c->color==RED)return node(c->lch,c->rch,BLACK);
    return update(c);
  }
  
  /*
  pair<node_t*,node_t*> split(node_t *a,int k){
    //a=update(a);
    if(k==0)return make_pair((node_t*)NULL,a);
    if(size(a)<=k)return make_pair(a,(node_t*)NULL);

    if(size(a->lch)>=k){
      pair<node_t*,node_t*>p=split(a->lch,k);
      return make_pair(p.first,merge(p.second,a->rch));
    } else {
      pair<node_t*,node_t*>p=split(a->rch,k-size(a->lch));
      return make_pair(merge(a->lch,p.first),p.second);
    }
    //return make_pair(update(a->lch),update(a->rch));
  }
  */
  pair<node_t*,node_t*> split(node_t *a,int k){
    //a=update(a);
    if(k==0)return make_pair((node_t*)NULL,a);
    if(size(a)==k)return make_pair(a,(node_t*)NULL);

    if(k<size(a->lch)){
      pair<node_t*,node_t*>p=split(a->lch,k);
      return make_pair(p.first,merge(p.second,a->rch));    
    } 
    else if(k>size(a->lch)){
      pair<node_t*,node_t*>p=split(a->rch,k-size(a->lch));     
      return make_pair(merge(a->lch,p.first),p.second);
    }
    return make_pair(a->lch,a->rch);
  }
  
  void insert(int k,int val){ root=insert(root,k,val); }
  void erase(int k){ root=erase(root,k); }
  node_t *find(int k){ return find(root,k); }
  
  void update(int id,int val){
    erase(id);
    insert(id,val);
  }
  
  int rmq(node_t *t, int l,int r){
    if(r<=0 || size(t)<=l)return INF;
    if(l<=0 && size(t)<=r)return mini(t);
    int szl=size(t->lch);
    int vl=rmq(t->lch,l,r);
    int vr=rmq(t->rch,l-szl,r-szl);
    return min(vl,vr);
  }
  
  int rangeMinimumQuery(int l,int r){
    
    return rmq(root,l,r);

    pair<node_t *,node_t *>s1,s2;
    s2=split(root,r);
    s1=split(s2.first,l);
    int res=mini(s1.second);
    root=merge(s1.first,merge(s1.second,s2.second));
    return res;
  }
  
  void revolve(int l,int r,int t){
    t%=(r-l);
    pair<node_t*, node_t*>a,b,c;
    c=split(root, r);
    b=split(c.first, r-t);
    a=split(b.first, l);
    root=merge(a.first, b.second);
    root=merge(root, a.second);
    root=merge(root, c.second);
  }

  int getSize(){
    return size(root);
  }
};


int main(void){

  int n,q;
  RedBlackTree t;
  
  cin >> n >> q;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    t.insert(i,a);
  }

  for(int i=0;i<q;i++){
    /*
    for(int j=0;j<n;j++){
      cout << t.find(j)->val << " ";
    }
    cout << endl;
    */
    int x,y,z;
    cin >> x >> y >> z;
    if(x==0){
      //cout << "revolve [" << y << "," << z+1 << ")" << endl;
      t.revolve(y,z+1,1);
    }
    if(x==1){
      //cout << "min [" << y << "," << z+1 << ")" << endl;
      cout << t.rangeMinimumQuery(y,z+1) << endl;
    }
    if(x==2){
      //cout << "update " << y << " " << z << endl;
      t.update(y,z);
    }
  }
  /*
    for(int j=0;j<n;j++){
    cout << t.find(j)->val << " ";
    }
    cout << endl;
  */

  return 0;
}