Problem p03938 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int, int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff;        // beware overflow
const LL INF = 0x7fffffffffffffff; // beware overflow
#define mem(x, y) memset(x, (y), sizeof(x));
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
  s << "[ ";
  for (auto it : c)
    s << it << " ";
  s << "]";
  return s;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &st) {
  o << "{";
  for (auto it = st.begin(); it != st.end(); it++)
    o << (it == st.begin() ? "" : ", ") << *it;
  return o << "}";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &mp) {
  o << "{";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    o << (it == mp.begin() ? "" : ", ") << it->fi << ":" << it->se;
  }
  o << "}";
  return o;
}
inline LL getint() {
  LL _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
#define maxn 200005
int b[maxn], a[maxn];
int main() {
  int n = getint();
  int cur = 2 + (n - 1) * (n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    x--;
    // a[x] in [ 1+n*(x-1) , n*(x-1)+1+n )
    for (int j = 1 + n * x; j < n * x + 1 + n; j++) {
      for (int k = 1 + n * (n - 1 - x); k < 1 + n * (n - 1 - x) + n; k++) {
        if (k + j == cur)
          a[x] = j, b[x] = k;
      }
    }
    cur++;
  }
  for (int i = 0; i < n; i++)
    printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
  for (int i = 0; i < n; i++)
    printf("%d%c", b[i], i == n - 1 ? '\n' : ' ');
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int, int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff;        // beware overflow
const LL INF = 0x7fffffffffffffff; // beware overflow
#define mem(x, y) memset(x, (y), sizeof(x));
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
  s << "[ ";
  for (auto it : c)
    s << it << " ";
  s << "]";
  return s;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &st) {
  o << "{";
  for (auto it = st.begin(); it != st.end(); it++)
    o << (it == st.begin() ? "" : ", ") << *it;
  return o << "}";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &mp) {
  o << "{";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    o << (it == mp.begin() ? "" : ", ") << it->fi << ":" << it->se;
  }
  o << "}";
  return o;
}
inline LL getint() {
  LL _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
#define maxn 200005
int b[maxn], a[maxn];
int main() {
  int n = getint();
  int cur = 2 + (n - 1) * (n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    x--;
    a[x] = 1 + n * x;
    b[x] = cur - a[x];
    cur++;
  }
  for (int i = 0; i < n; i++)
    printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
  for (int i = 0; i < n; i++)
    printf("%d%c", b[i], i == n - 1 ? '\n' : ' ');
}