96分求助,WA#3,悬赏1关注
查看原帖
96分求助,WA#3,悬赏1关注
288506
OutsideR_楼主2023/11/19 10:19
#include <iostream>
#include <algorithm>
using namespace std;
long long n,Q,k,x,y,t,k1=1;
struct node{
	long long n;
	long long ii;		
};
node a[8005],tt[8005];
long long zz[8005];
bool cmp(node ta,node tb){
	if(ta.n<tb.n)return 1;
	if(ta.n==tb.n){
		if(ta.ii<tb.ii)return 1;
		return 0;
	}
	return 0;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>Q;
	for(int i=1;i<=n;i++){
		cin>>a[i].n;
		a[i].ii=i;
		tt[i]=a[i];
	}
	while(Q--){
		cin>>k;
		if(k==1){
			cin>>x>>y;
			a[x].n=y;
			tt[zz[x]].n=y;
		}
		if(k==2){
			cin>>x;
			if(k1==1){
				stable_sort(tt+1,tt+1+n,cmp);
				for(int i=1;i<=n;i++)zz[tt[i].ii]=i;
			}
			t=lower_bound(tt+1,tt+1+n,a[x],cmp)-tt;
			cout<<t<<endl;
			
		}
		k1=k;
	}
	return 0;
}

RT,#3一直过不去

2023/11/19 10:19
加载中...