跳到正文

个人记录

梁思宇要的

Cube_Dev约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年10月20日
收录
2025年12月12日
更新
2026年10月4日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

#include <bits/stdc++.h> using namespace std; const int MAXN=8005; int n,q; int t[MAXN]; struct node{ int pre,id; }a[MAXN]; bool cmp(node x,node y){ if(x.pre!=y.pre) return x.pre<y.pre; return x.id<y.id; } int main(){ scanf(“%d%d”,&n,&q); for(int i=1;i<=n;i++){ scanf(“%d”,&a[i].pre); a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) t[a[i].id]=i; for(int i=1;i<=q;i++){ int opt,x,v; scanf(“%d”,&opt); if(opt==1){ scanf(“%d%d”,&x,&v); a[t[x]].pre=v; for(int j=n;j>=2;j—) if(cmp(a[j],a[j-1])){ node k=a[j]; a[j]=a[j-1]; a[j-1]=k; } for(int j=2;j<=n;j++) if(cmp(a[j],a[j-1])){ node k=a[j]; a[j]=a[j-1]; a[j-1]=k; } for(int i=1;i<=n;i++) t[a[i].id]=i; } else{ scanf(“%d”,&x); printf(“%d\n”,t[x]); } } return 0; }

原文