参考程序:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mn = 1e5 + 10;
ll n, t, a[mn];
set<pair<ll, ll>> b;
signed main()
{
cin.tie(0)->ios::sync_with_stdio(false);
cin >> n;
for (ll i = 1; i <= n; ++i)
{
cin >> a[i];
}
for (ll i = 1, v; i <= n; ++i)
{
cin >> v;
b.insert({v, i});
}
for (ll i = 1; i <= n; ++i)
{
auto pr = b.lower_bound({a[i], 0});
a[i] = pr->second;
b.erase(pr);
cout << a[i] << ' ';
}
cout << '\n';
return 0;
}
本题数据生成器:
from random import *
idx = 1
def wris(r):
global idx
with open('s3-%d.in' % idx, 'w') as f:
f.write(r)
idx += 1
def wri(a, b):
r = '%d\n' % len(a)
for i in a:
r += '%d ' % i
r = r[:-1] + '\n'
for i in b:
r += '%d ' % i
wris(r)
MX, MN = int(1e9), int(1e5)
def gen(n=MN, mi=1, mx=MX):
b = [randint(mi, mx) for i in range(n)]
a = b[:]
shuffle(a)
wri(a, b)
gen(1, 1)
wri([580, 580], [580, 580])
gen(MN, MX)
inc1 = [i for i in range(1, 1 + MN)]
dec1 = inc1[:]
dec1.reverse()
wri(inc1, dec1)
wri(dec1, inc1)
inc2 = [randint(1, MX) for i in range(1, 1 + MN)]
inc2.sort()
dec2 = inc2[:]
dec2.reverse()
wri(inc2, dec2)
wri(dec2, inc2)
inc3 = [randint(1, 2000) for i in range(1, 1 + MN)]
inc3.sort()
dec3 = inc3[:]
dec3.reverse()
wri(inc3, dec3)
wri(dec3, inc3)
gen()
for n, mi, mx in ((MN, 1, 100), (MN, 1, 1000), (MN, 1, MN), (MN, 1, 2 * MN)):
gen(n, mi, mx)
for i in range(3):
n = randint(1, MN)
mi, mx = randint(1, MX), randint(1, MX)
if mi > mx:
mi, mx = mx, mi
gen(n, mi, mx)