求助,CSP
  • 板块灌水区
  • 楼主zq2070sdhz
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/10/23 19:42
  • 上次更新2023/11/4 02:38:45
查看原帖
求助,CSP
427560
zq2070sdhz楼主2021/10/23 19:42

pjpj,第二题

#include<bits/stdc++.h>
using namespace std;
int n,q,id[10005],a[10005];
struct tmp{
    int num,id;
}temp[10005];
bool cmp(tmp x,tmp y){
    return x.num<y.num;
}
int main(){
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++){cin>>a[i];id[i]=i;}
    for(int i=1;i<=q;i++){
        int d,x,v;cin>>d;
        if(d==1){cin>>x>>v;a[x]=v;}
        else if(d==2){
            cin>>x;
            for(int j=1;j<=n;j++) temp[j].num=a[j],temp[j].id=id[j];
            sort(temp+1,temp+n+1,cmp);
            for(int j=1;j<=n;j++){
                if(temp[j].num==a[x]&&temp[j].id==id[x]){cout<<j<<endl;break;}
            }
        }
    }
    return 0;
}

2021/10/23 19:42
加载中...