Files
python/TangDou/CSP-J/J2-2021/2_1_cin_YouHua.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 8010;
struct Node {
int id;
int value;
bool operator<(const Node &t) const {
if (value == t.value) return id < t.id;
return value < t.value;
}
} a[N];
int n, q;
/*
测试结果:
1、不加cin优化:有时3个点TLE,有时1个点TLE,有时AC
2、加了cin优化:每次AC
结论:cin优化有必要的!
*/
int main() {
//加快读入
cin.tie(0), ios::sync_with_stdio(false);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i].value;
a[i].id = i;
}
sort(a + 1, a + 1 + n);
while (q--) {
int op, x, v;
cin >> op;
if (op == 1) {
cin >> x >> v;
for (int i = 1; i <= n; i++)
if (a[i].id == x) {
a[i].value = v;
break;
}
sort(a + 1, a + 1 + n);
} else {
cin >> x;
for (int i = 1; i <= n; i++)
if (a[i].id == x) {
printf("%d\n", i);
break;
}
}
}
return 0;
}