Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define endl "\\n"

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define mi map<int, int>
#define pi pair<int, int>

#define Fori(i, a, b) for (int i = a; i < b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)

#define pb push_back
#define mp make_pair

#define read(a, n)                                                             \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a)                                                            \\
  for (auto it = a.begin(); it != a.end(); it++) {                             \\
    cout << it->first << "  " << it->second << endl;                           \\
  }
#define printVector(a)                                                         \\
  for (auto it = a.begin(); it != a.end(); it++) {                             \\
    cout << *it << endl;                                                       \\
  }

using namespace std;
int main() {
  IOS int n;
  cin >> n;
  vi a(n);
  read(a, n);
  ll ans = a[0];
  Fori(i, 1, n) { ans ^= a[i]; }
  Fori(i, 0, n) {
    ll fin = ans ^ a[i];
    cout << fin << " ";
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define endl "\\n"

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define mi map<int, int>
#define pi pair<int, int>

#define Fori(i, a, b) for (int i = a; i < b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)

#define pb push_back
#define mp make_pair

#define read(a, n)                                                             \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a)                                                            \\
  for (auto it = a.begin(); it != a.end(); it++) {                             \\
    cout << it->first << "  " << it->second << endl;                           \\
  }
#define printVector(a)                                                         \\
  for (auto it = a.begin(); it != a.end(); it++) {                             \\
    cout << *it << endl;                                                       \\
  }

using namespace std;
int main() {
  IOS int n;
  cin >> n;
  vi a(n);
  read(a, n);
  Fori(i, 0, n) {
    ll ans = -1;
    Fori(j, 0, n) {
      if (j == i)
        continue;
      if (ans == -1) {
        ans = a[j];
        continue;
      }
      ans ^= a[j];
    }
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}