'commit'
This commit is contained in:
53
TangDou/CSP-J/J2-2021/2_1_cin.cpp
Normal file
53
TangDou/CSP-J/J2-2021/2_1_cin.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#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 >> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user