插入排序
13 x AC, 12 x TLE
#include <bits/stdc++.h>
using namespace std;
struct Num {
int e;
int id;
bool operator<(const Num& rhs) const {
if (e != rhs.e) {
return e < rhs.e;
}
return id < rhs.id;
}
bool operator==(const Num& rhs) const {
return e == rhs.e && id == rhs.id;
}
void swap(Num &a, Num &b) {
Num t = a;
a = b;
b = t;
}
};
Num a[100000], b[100000];
bool is = true;
void f1(int , int );
int f2(int );
int n, q;
int main(){
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i].e;
a[i].id = i;
}
while (q--) {
int p;
cin >> p;
if (!(p - 1)) {
int x, v;
cin >> x >> v;
f1(x, v);
} else {
int x;
cin >> x;
cout << f2(x) << endl;
}
}
return 0;
}
void f1(int x, int v) {
a[x].e = v;
is = true;
}
int f2(int x) {
if (b) {
for (int i = 1; i <= n; i++) {
b[i] = a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = i; j >= 2; j--) {
if (b[j] < b[j - 1]) {
swap(b[j], b[j - 1]);
}
}
}
is = false;
}
for (int i = 1; i <= n; i++) {
if (b[i] == a[x]) {
return i;
}
}
}