记录编号 571636 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 [CSP 2021J]插入排序 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 6.308 s
提交时间 2022-06-01 20:16:48 内存使用 3.71 MiB
显示代码纯文本
  1. #pragma GCC optimize(2)
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int maxn = 8e3 + 5;
  5. int a[maxn],cnt[maxn];
  6. int n,m;
  7. int read() {
  8. int s = 0;
  9. char c = getchar();
  10. for(;!isdigit(c);c = getchar());
  11. for(;isdigit(c);c = getchar())s = (s << 1) + (s << 3) + (c ^ '0');
  12. return s;
  13. }
  14. void write(int x) {
  15. if(x > 9)write(x / 10);
  16. putchar(x % 10 + '0');
  17. return ;
  18. }
  19. void output(int x) {
  20. write(x);
  21. puts("");
  22. return ;
  23. }
  24. void modify(int x,int v,int k) {
  25. for(int i = 1;i <= n;++ i) {
  26. if(i == x)continue ;
  27. cnt[i] += k * (v < a[i]||(a[i] == v&&x <= i));
  28. }
  29. return ;
  30. }
  31. int main() {
  32. freopen("csp2021pj_sort.in","r",stdin);
  33. freopen("csp2021pj_sort.out","w",stdout);
  34. n = read();
  35. m = read();
  36. for(int i = 1;i <= n;++ i) {
  37. a[i] = read();
  38. }
  39. for(int i = 1;i <= n;++ i) {
  40. for(int j = 1;j <= n;++ j) {
  41. cnt[i] += (a[j] < a[i]||(a[i] == a[j]&&j <= i));
  42. }
  43. }
  44. while(m --) {
  45. int v,op = read(),x = read();
  46. if(op & 1) {
  47. v = read();
  48. modify(x , a[x] , -1);
  49. modify(x , a[x] = v , 1);
  50. cnt[x] = 0;
  51. for(int i = 1;i <= n;++ i)cnt[x] += (a[i] < a[x]||(a[i] == a[x]&&i <= x));
  52. }
  53. else {
  54. output(cnt[x]);
  55. }
  56. }
  57. return 0;
  58. }