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

#include <bits/stdc++.h>

using namespace std;

void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
#define endl "\\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll, ll>
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define tll tuple<ll, ll, ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cases                                                                  \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define array(a, n)                                                            \\
  vll a(n);                                                                    \\
  rep(i, 0, n) cin >> a[i];
#define sortall(a) sort(a.begin(), a.end())
#define printall(a)                                                            \\
  rep(i, 0, a.size()) cout << a[i] << " ";                                     \\
  cout << endl;

// --------------- My Template End --------------- //
bool isprime(ll n) {
  if (n % 2 == 0)
    return false;
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // input();
  ll n;
  cin >> n;
  array(a, n);
  ll temp = 0;
  vector<ll> ans(n);
  rep(j, 0, n) { temp ^= a[j]; }

  rep(i, 0, n) { ans[i] = temp ^ a[i]; }

  printall(ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
#define endl "\\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll, ll>
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define tll tuple<ll, ll, ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cases                                                                  \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define array(a, n)                                                            \\
  vll a(n);                                                                    \\
  rep(i, 0, n) cin >> a[i];
#define sortall(a) sort(a.begin(), a.end())
#define printall(a)                                                            \\
  rep(i, 0, a.size()) cout << a[i] << " ";                                     \\
  cout << endl;

// --------------- My Template End --------------- //
bool isprime(ll n) {
  if (n % 2 == 0)
    return false;
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  array(a, n);

  vector<ll> ans(n);
  rep(i, 0, n) {
    ll temp = 0;
    rep(j, 0, n) {
      if (i != j) {
        temp ^= a[j];
      }
    }
    ans[i] = temp;
  }
  printall(ans);
}