1、数对可用于数组排序中,并且可记忆化排序前的元素下标
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
pair<int, int> a[N];
void solve() {ll n;cin >> n;for (ll i = 1; i <= n; i++) {cin >> a[i].first;a[i].second = i;}sort(a + 1, a + 1 + n);cout << "元素:";for (ll i = 1; i <= n; i++) {cout << a[i].first << " ";}cout << endl;cout << "下标:";for (ll i = 1; i <= n; i++) {cout << a[i].second << " ";}cout << endl;
}
int main() {std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);ll t=1;//cin >> t;while (t--) {solve();}
}


2、例题

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
pair<int, int> a[N];
int main(){int n;cin >> n;for (int i = 1; i <= n; i++){cin >> a[i].first;a[i].second = i;}sort(a + 1, a + 1 + n);for (int i = 2; i <= n; i++){if (a[i].first == a[i - 1].first){cout << "NO";return 0;}}cout << "YES" << '\n';for (int i = 1; i <= n; i++){cout << a[i].second << " ";}return 0;
}