//include //------------------------------------------ #include using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout< inline T sqr(T x) {return x*x;} //typedef //------------------------------------------ typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair P; typedef long long ll; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const long long INF = 1000000007; //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; // chmax chmin template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template struct SegmentTree { private: using Func = function; int n; vector node; T init_v; Func func; public: SegmentTree(vector a, Func _func, T _init_v) { int sz = a.size(); n = 1; init_v = _init_v; func = _func; while (n < sz) n <<= 1; node.resize(2 * n - 1, init_v); for (int i = 0; i < sz; i++) node[i + n - 1] = a[i]; for (int i = n - 2; i >= 0; i--) node[i] = func(node[i * 2 + 1], node[i * 2 + 2]); } void update(int pos, T v) { int k = pos + n - 1; node[k].first = v.first; while (k > 0) { k = (k - 1) / 2; node[k] = func(node[k * 2 + 1], node[k * 2 + 2]); } } T get(int pos) { int k = pos + n - 1; return node[k]; } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return init_v; if (a <= l && r <= b) return node[k]; T lv = query(a, b, k * 2 + 1, l, (l + r) / 2); T rv = query(a, b, k * 2 + 2, (l + r) / 2, r); return func(lv, rv); } int size(){ return n; } }; P _calc(P a, P b){ return a.first > b.first ? b : a; } int main(void){ int n, q; cin >> n >> q; vector

a(n); REP(i,n){cin >> a[i].first; a[i].second = i+1;} SegmentTree

st(a, _calc, P(n+1, n+1)); REP(i,q){ int c, l, r; cin >> c >> l >> r; l--; r--; if(c == 2) cout << st.query(l, r+1, 0, 0, st.size()).second << endl; else{ P al = st.get(l), ar = st.get(r); st.update(l, ar); st.update(r, al); } } return 0; }