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)

  1. static final int N = 20010;
  2. static int[] a = new int[N], b = new int[N];
  3. static int[] p = new int[N];
  4. static int[] x = new int[N];
  5. static int n;
  6. static void solve() {
  7. n = ni();
  8. for (int i = 1; i <= n; i++)
  9. p[i] = ni();
  10. for (int i = 1; i <= n; i++) {
  11. x[p[i]] = i;
  12. b[i] = n * (-i);
  13. }
  14. for (int i = 1; i <= n; i++) {
  15. a[i] = x[i] - b[i];
  16. b[i] += (n + 1) * n;
  17. }
  18. for (int i = 1; i <= n; i++) {
  19. out.print(a[i] + " ");
  20. }
  21. out.println();
  22. for (int i = 1; i <= n; i++) {
  23. out.print(b[i] + " ");
  24. }
  25. }