AtCoder Grand Contest 007 B - Construct Sequences
固定a[p[i]] + b[p[i]]
和b[i]
令a[p[i]] + b[p[i]]
为1, 2, 3...
,b[i]
为-1 * n, -2 * n, -3 * n...
(计算出a[i]
,然后再考虑偏移)
时间复杂度:O(n)
空间复杂度:O(n)
static final int N = 20010;
static int[] a = new int[N], b = new int[N];
static int[] p = new int[N];
static int[] x = new int[N];
static int n;
static void solve() {
n = ni();
for (int i = 1; i <= n; i++)
p[i] = ni();
for (int i = 1; i <= n; i++) {
x[p[i]] = i;
b[i] = n * (-i);
}
for (int i = 1; i <= n; i++) {
a[i] = x[i] - b[i];
b[i] += (n + 1) * n;
}
for (int i = 1; i <= n; i++) {
out.print(a[i] + " ");
}
out.println();
for (int i = 1; i <= n; i++) {
out.print(b[i] + " ");
}
}