'commit'
This commit is contained in:
54
TangDou/CSP-J/J2-2021/2_0.cpp
Normal file
54
TangDou/CSP-J/J2-2021/2_0.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 8010;
|
||||
|
||||
struct Node {
|
||||
int value;
|
||||
int id;
|
||||
} a[N];
|
||||
|
||||
bool cmp(Node &a, Node &b) {
|
||||
if (a.value == b.value) return a.id < b.id;
|
||||
return a.value < b.value;
|
||||
}
|
||||
|
||||
int n;
|
||||
int q;
|
||||
|
||||
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, cmp);
|
||||
|
||||
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, cmp);
|
||||
} else {
|
||||
cin >> x;
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i].id == x) {
|
||||
cout << i << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user