社区讨论

85求条

B2167查找最后一个出现的位置参与者 3已保存回复 9

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@mlh9k4xj
此快照首次捕获于
2026/02/11 08:00
上周
此快照最后确认于
2026/02/12 17:20
7 天前
查看原帖
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[1000010],q;
map<int,int>mp;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
inline void write(int x){
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    n=read();
    q=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		mp[a[i]]=i;
	}
	for(int i=1;i<=q;i++){
		int t;
		t=read();
        int ans=(mp[t]==0?-1:mp[t]);
        if(ans!=-1) write(ans);
        else{
            putchar('-');
            putchar('1');
        }
        putchar('\n');
	}
	return 0;}
TLE

回复

9 条回复,欢迎继续交流。

正在加载回复...