Algorithm/insert-sort/main.cc
LittleSheep b2505a5361
P7912 100pts 队列 (used to be using vector, TLE)
2024-10-21 21:41:32 +08:00

38 lines
926 B
C++

#include <iostream>
using namespace std;
const int N = 10005;
pair<int, int> arr[N];
int b[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i].first);
arr[i].second = i;
}
sort(arr + 1, arr + n + 1);
for (int i = 1; i <= n; i++) b[arr[i].second] = i;
while (m--) {
int op, x, y;
scanf("%d", &op);
if (op == 1) {
scanf("%d%d", &x, &y);
arr[b[x]].first = y;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]);
}
for (int i = n - 1; i >= 1; i--) {
if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]);
}
for (int i = 1; i <= n; i++) b[arr[i].second] = i;
} else {
scanf("%d", &x);
printf("%d\n", b[x]);
}
}
return 0;
}