#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int tree[1 << 20]; int a[100001]; int init(int node, int start, int end) { if (start == end) { return tree[node] = start; } int mid = (start + end) / 2; int l = init(2 * node, start, mid); int r = init(2 * node + 1, mid + 1, end); if (a[l] > a[r]) { tree[node] = r; } else if (a[l] < a[r]) { tree[node] = l; } else { tree[node] = min(l, r); } return tree[node]; } void update(int node, int start, int end, int index) { if (index < start || index > end) { return; } if (start == end) { tree[node] = start; return; } if (start != end) { int mid = (start + end) / 2; update(2 * node, start, mid, index); update(2 * node + 1, mid + 1, end, index); } int x = tree[2 * node]; int y = tree[2 * node + 1]; //cout << node << ' ' << start << ' ' << end << ' ' << tree[node] << '\n'; //cout << 2*node << ' ' << start << ' ' << (start+end)/2 << ' ' << x << ' ' << a[x] << '\n'; //cout << 2*node+1 << ' ' << (start+end)/2 + 1 << ' ' << end << ' ' << y << ' ' << a[y] << '\n'; if (a[x] < a[y]) { tree[node] = x; } else if (a[x] > a[y]) { tree[node] = y; } else { tree[node] = min(x, y); } } int find(int node, int start, int end, int left, int right) { if (right < start || end < left) { return 0; } if (left <= start && end <= right) { return tree[node]; } int mid = (start + end) / 2; int x = find(2 * node, start, mid, left, right); int y = find(2 * node + 1, mid + 1, end, left, right); //cout << node << ' ' << start << ' ' << end << ' ' << tree[node] << '\n'; //cout << 2*node << ' ' << start << ' ' << (start+end)/2 << ' ' << x << ' ' << a[x] << '\n'; //cout << 2*node+1 << ' ' << (start+end)/2 + 1 << ' ' << end << ' ' << y << ' ' << a[y] << '\n'; if (a[x] < a[y]) { return x; } else if (a[x] > a[y]) { return y; } return min(x, y); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m, x, y, z; cin >> n >> m; for (int i = 0; i <= 100000; i++) { a[i] = 2e9; } for (int i = 1; i <= n; i++) { cin >> a[i]; } init(1, 0, n); for (int i = 0; i < m; i++) { cin >> x >> y >> z; if (x == 1) { int tmpa = a[y]; int tmpb = a[z]; a[y] = tmpb; a[z] = tmpa; update(1, 0, n, y); update(1, 0, n, z); //init(1,0,n); } else { cout << find(1, 0, n, y, z) << '\n'; } } return 0; }