提交时间:2021-12-06 18:26:24
运行 ID: 33505
#include<bits/stdc++.h> using namespace std; int n, q, s; int index[100005]; struct node { int a, id; bool operator <(const node &n)const { return a<n.a || (a==n.a && id<n.id); } } arr[100005]; int main() { // freopen("sort.in","r",stdin); // freopen("sort.out","w",stdout); scanf("%d%d", &n, &q); for(int i=1; i<=n; i++) { arr[i].id = i; scanf("%d", &arr[i].a); } sort(arr+1, arr+n+1); for(int i=1; i<=n; i++) { index[arr[i].id] = i; } while(q--) { int op, x, y; scanf("%d%d", &op, &x); if(op == 1) { scanf("%d", &y); s = index[x]; arr[index[x]].a = y; for(int i=s-1; i>=1; i--) { if(arr[i].a>y || (arr[i].a==y && x<arr[i].id)) { swap(index[x], index[arr[i].id]); swap(arr[s], arr[i]); s = index[x]; } else break; } for(int i=s+1; i<=n; ++i) { if(arr[i].a<y || (arr[i].a==y && x>arr[i].id)) { swap(index[x], index[arr[i].id]); swap(arr[s], arr[i]); s = index[x]; } else break; } } else printf("%d\n", index[x]); } return 0; }