You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 8010;
int b[N]; // 保存排序后的位置
struct Node {
int num; // 数值
int id; // 原来的位置
} a[N];
bool cmp(Node &a, Node &b) {
if (a.num == b.num)
return a.id < b.id; // 值一样,号小的在前
else
return a.num < b.num; // 值不一样,小的在前
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].num);
a[i].id = i;
}
sort(a + 1, a + n + 1, cmp); // 首次排序
// 按原来的id获取现在的位置
for (int i = 1; i <= n; i++) b[a[i].id] = i; // 把排序后的位置存到b数组里
while (m--) {
int op;
scanf("%d", &op);
if (op == 1) { // 操作1
int x, v;
scanf("%d %d", &x, &v);
a[b[x]].num = v; // 更新a数组的值
for (int i = 1; i <= n; i++) // 插入排序
for (int j = i; j >= 2; j--) {
// 按值的大小排序,值相同的按原来的位置排序
if (cmp(a[j], a[j - 1])) {
swap(a[j], a[j - 1]); // 交换
swap(b[a[j].id], b[a[j - 1].id]); // 将b数组中的位置也做下交换
} else
break; // break可以节省时间
}
} else {
int x;
scanf("%d", &x);
printf("%d\n", b[x]);
}
}
return 0;
}