Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34906 xujindong [CSP-J2021]插入排序 C++ 通过 100 199 MS 348 KB 1036 2021-12-12 22:55:11

Tests(25/25):


#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 temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } for(int j=2; j<=n; j++) if(cmp(a[j],a[j-1])) { node temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } for(int i=1; i<=n; i++) t[a[i].id]=i; } else { scanf("%d",&x); printf("%d\n",t[x]); } } return 0; }


测评信息: