提交时间:2021-12-08 13:49:31
运行 ID: 33859
#include <iostream> #include <algorithm> using namespace std; const int N = 8010; struct CNF { int x,id; }a[N]; bool cmp(const CNF& x,const CNF& y) { if(x.x != y.x) return x.x < y.x; return x.id < y.id; } int b[N]; int main() { int n,q,i; cin>>n>>q; for(i = 1;i <= n;i++) { cin>>a[i].x; a[i].id = i; } sort(a + 1,a + n + 1,cmp); for(i = 1;i <= n;i++) b[a[i].id] = i; while(q--) { int op; cin>>op; if(op == 1) { int p,y; cin>>p>>y; a[b[p]].x = y; for(i = 2;i <= n;i++) if(cmp(a[i],a[i - 1])) swap(a[i],a[i-1]); for(i = n;i >= 1;i--) if(cmp(a[i],a[i - 1])) swap(a[i],a[i - 1]); for(i = 1;i <= n;i++) b[a[i].id]=i; } else { int x; cin>>x; cout<<b[x]<<endl; } } return 0; }