社区讨论
52分超时求调
P7910[CSP-J 2021] 插入排序参与者 7已保存回复 13
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 13 条
- 当前快照
- 1 份
- 快照标识符
- @lo8w8zrp
- 此快照首次捕获于
- 2023/10/28 01:35 2 年前
- 此快照最后确认于
- 2023/10/28 01:35 2 年前
CPP
#include<iostream>
#include<algorithm>
#define N 50001
#define re register
using namespace std;
long long n,q,c,a[N],b[N];
int main(){
scanf("%lld%lld",&n,&q);
for(re int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(re int i=1;i<=q;i++){
scanf("%lld",&c);
if(c==1){
scanf("%lld",&c);
scanf("%lld",&a[c]);
}
else{
scanf("%lld",&c);
for(re int j=1;j<=n;j++) b[j]=a[j];
for(re int j=1;j<=n;j++)
for(re int k=j;k>=2;k--)
if(b[k]<b[k-1]){
if(k==c) c--;
else if(k-1==c) c++;
int t1=b[k-1];
b[k-1]=b[k];
b[k]=t1;
}
printf("%lld\n",c);
}
}
return 0;
}
回复
共 13 条回复,欢迎继续交流。
正在加载回复...