可能不是正解,但十分希望大佬能帮忙调一下代码,过个样例
查看原帖
可能不是正解,但十分希望大佬能帮忙调一下代码,过个样例
372172
Q__A__Q楼主2022/8/12 23:43

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll

const int maxn=1e4+10;
const int inf=1e9+7;
int n,q,ans;

struct node1 {
	int x,rank;
} b[maxn];
struct node2 {
	int x,num;
}a[maxn];

inline int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}

inline void write(int x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

inline bool cmp(node2 p,node2 q) {
	if(p.x==q.x)
		return p.num<q.num;
	else return p.x<q.x;
}

signed main() {
//	freopen(".in","r",stdin);
//	freopen("sort.out","w",stdout);
	n=read(),q=read();
	for(int i=1; i<=n; ++i) {
		b[i].x=read();
		a[i].x=b[i].x;
		a[i].num=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i)
		b[a[i].num].rank=i;
//	for(int i=1;i<=n;++i)
//		cout<<b[i].x<<' '<<b[i].rank<<' '<<b[i].to<<endl;
	for(int i=1; i<=q; ++i) {
		int tmp=read();
		if(tmp==1) {
			int u=read(),v=read();
			int t=b[u].rank,j;
			for(j=t+1;j<=n;++j) {
				if(a[j].x<v||(a[j].x==v&&a[j].num>u)) b[a[j].num].rank--;
				else break;
			}
			b[u].rank=j,b[u].x=v;
		}
		else if(tmp==2) {
			int u=read();
			write(b[u].rank);
			puts("");
		}
	}
	return 0;
}

样例download

感激不尽!!

2022/8/12 23:43
加载中...