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 <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>

#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)









using T = long long;

class xorshift{
private:
    uint64_t x;
public:
    xorshift(){
        random_device rnd;
        mt19937 mt(rnd());
        x = mt();
        for(int i = 0; i < 50; i++){
            random();
        }
    }
    uint64_t random(){
        x = x ^ (x << 7);
        return x = x ^ (x >> 9);
    }
};



struct SumMonoid{
    static constexpr T id(){
        return 0;
    }
    static T op(T a, T b){
        return a + b;
    }
};

struct MinMonoid{
    static constexpr T id(){
        return INF;
    }
    static T op(T a, T b){
        return min(a, b);
    }
};

struct UpdateMonoid{
    static constexpr T id(){
        return INF;
    }
    static T op(T a, T b){
        return b;
    }
};

struct Modifier{
    static T op(T a, T b, int sz){
        return b == UpdateMonoid::id() ? a : b;
    }
};

template<class Monoid, class OperatorMonoid>
class ImplictTreap {
private:
    xorshift rnd;
    
    struct Node{
        T value, acc, lazy;
        int priority, cnt;
        bool rev;
        Node *l, *r;
        Node(T value, int priority) : value(value), acc(Monoid::id()), lazy(OperatorMonoid::id()), priority(priority), cnt(1), rev(false), l(nullptr), r(nullptr) {};
    } *root = nullptr;
    
    using Tree = Node *;
    
    int cnt(Tree t){
        return t ? t->cnt : 0;
    }
    
    T acc(Tree t){
        return t ? t->acc : Monoid::id();
    }
    
    void update_cnt(Tree t){
        if(t){
            t->cnt = 1 + cnt(t->l) + cnt(t->r);
        }
    }
    
    void update_acc(Tree t){
        if(t){
            t->acc = Monoid::op(acc(t->l), Monoid::op(t->value, acc(t->r)));
        }
    }
    
    void pushup(Tree t){
        update_cnt(t);
        update_acc(t);
    }
    
    void pushdown(Tree t){
        if(t && t->rev){
            t->rev = false;
            swap(t->l, t->r);
            if(t->l) t->l->rev ^= 1;
            if(t->r) t->r->rev ^= 1;
        }
        if(t && t->lazy != OperatorMonoid::id()){
            if(t->l){
                t->l->lazy = OperatorMonoid::op(t->l->lazy, t->lazy);
                t->l->acc = Modifier::op(t->l->acc, t->lazy, cnt(t->l));
            }
            if(t->r){
                t->r->lazy = OperatorMonoid::op(t->r->lazy, t->lazy);
                t->r->acc = Modifier::op(t->r->acc, t->lazy, cnt(t->r));
            }
            t->value = Modifier::op(t->value, t->lazy, 1);
            t->lazy = OperatorMonoid::id();
        }
        pushup(t);
    }
    
    void split(Tree t, T key, Tree &l, Tree &r){
        if(!t){
            l = r = nullptr;
            return;
        }
        pushdown(t);
        int implicit_key = cnt(t->l) + 1;
        if(key < implicit_key){
            split(t->l, key, l, t->l);
            r = t;
        }
        else{
            split(t->r, key - implicit_key, t->r, r);
            l = t;
        }
        pushup(t);
    }
    
    void merge(Tree& t, Tree l, Tree r){
        pushdown(l);
        pushdown(r);
        if(!l || !r){
            t = l ? l : r;
        }
        else if(l->priority > r->priority){
            merge(l->r, l->r, r);
            t = l;
        }
        else{
            merge(r->l, l, r->l);
            t = r;
        }
        pushup(t);
    }
    
    void insert(Tree &t, int key, Tree item){
        Tree t1, t2;
        split(t, key, t1, t2);
        merge(t1, t1, item);
        merge(t, t1, t2);
    }
    
    void erase(Tree& t, T key){
        Tree t1, t2, t3;
        split(t, key + 1, t1, t2);
        split(t1, key, t1, t3);
        merge(t, t1, t2);
    }
    
    void update(Tree t, int l, int r, T x){
        Tree t1, t2, t3;
        split(t, l, t1, t2);
        split(t2, r - l, t2, t3);
        t2->lazy = OperatorMonoid::op(t2->lazy, x);
        t2->acc = Modifier::op(t2->acc, x, cnt(t2));
        merge(t2, t2, t3);
        merge(t, t1, t2);
    }
    
    T query(Tree t, int l, int r){
        Tree t1, t2, t3;
        split(t, l, t1, t2);
        split(t2, r - l, t2, t3);
        T ret = t2->acc;
        merge(t2, t2, t3);
        merge(t, t1, t2);
        return ret;
    }
    
    int find(Tree t, T x, int offset, bool left = true){
        if(Monoid::op(t->acc, x) == x) return -1;
        
        if(left){
            if(t->l && Monoid::op(t->l->acc, x) != x){
                return find(t->l, x, offset, left);
            }
            else{
                return Monoid::op(t->value, x) != x ? offset + cnt(t->l) : find(t->r, x, offset + cnt(t->l) + 1, left);
            }
        }
        else{
            if(t->r && Monoid::op(t->r->acc, x) != x){
                return find(t->r, x, offset + cnt(t->l) + 1, left);
            }
            else{
                return Monoid::op(t->value, x) != x ? offset + cnt(t->l) : find(t->l, x, offset, left);
            }
        }
    }
    
    void reverse(Tree t, int l, int r){
        if(l > r) return;
        Tree t1, t2, t3;
        split(t, l, t1, t2);
        split(t2, r - l, t2, t3);
        t2->rev ^= 1;
        merge(t2, t2, t3);
        merge(t, t1, t2);
    }
    
    void rotate(Tree t, int l, int m, int r){
        reverse(t, l, r);
        reverse(t, l, l + r - m);
        reverse(t, l + r - m, r);
    }
    
    void dump(Tree t){
        if(!t) return;
        pushdown(t);
        dump(t->l);
        cerr << t->value << " ";
        dump(t->r);
    }
    
public:
    ImplictTreap(){}
    ImplictTreap(vector<T> as){
        ::reverse(as.begin(), as.end());
        for(T a : as){
            insert(0, a);
        }
    }
    
    int size(){
        return cnt(root);
    }
    
    void insert(int pos, T x){
        insert(root, pos, new Node(x, rnd.random()));
    }
    
    void update(int l, int r, T x){
        update(root, l, r, x);
    }
    
    void update(int pos, T x){
        update(root, pos, pos + 1, x);
    }
    
    T query(int l, int r){
        return query(root, l, r);
    }
    
    // 存在しない場合は-1
    int find(int l, int r, T x, bool left = true){
        Tree t1, t2, t3;
        split(root, l, t1, t2);
        split(t2, r - l, t2, t3);
        int ret = find(t2, x, l, left);
        merge(t2, t2, t3);
        merge(root, t1, t2);
        return ret;
    }
    
    void erase(int pos){
        erase(root, pos);
    }
    
    void reverse(int l, int r){
        reverse(root, l, r);
    }
    
    void rotate(int l, int m, int r){
        rotate(root, l, m, r);
    }
    
    void dump(){
        dump(root);
        cerr << endl;
    }
    
    T operator[](int pos){
        Tree t1, t2, t3;
        split(root, pos + 1, t1, t2);
        split(t1, pos, t1, t3);
        T ret = t3->acc;
        merge(t1, t1, t3);
        merge(root, t1, t2);
        return ret;
    }
};



int main(){
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    ImplictTreap<MinMonoid, UpdateMonoid> tree(a);
    REP(i, q){
        // tree.dump();
        ll x, y, z;
        cin >> x >> y >> z;
        if(x == 0){
            tree.rotate(y, z, z + 1);
        }
        else if(x == 1){
            cout << tree.query(y, z + 1) << endl;
        }
        else{
            tree.update(y, y + 1, z);
        }
    }
}