Files
python/TangDou/CSP-J/J2-2021/2_1_cin_YouHua.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

55 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}