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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define FOR(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
const long long INF = 1e12;
const long long MOD = 1e9 + 7;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];
  // int i=1;
  // int count=1;
  // while(i*=2){
  //     count++;
  //     if(i>1e9){
  //         cout<<count<<endl;
  //         break;
  //     }
  // }

  int sum = 0;
  rep(i, n) sum ^= a[i];

  rep(i, n) {
    // cout<<sum^10<<endl;
    int tmp = sum ^ a[i];
    cout << tmp << ' ';
    // cout<<sum^a[i]<<' ';
  }
  // rep(i,n){
  //     int res=0;
  //     rep(j,n){
  //         if(i==j) continue;
  //         res^=a[j];
  //     }
  //     cout<<res<<' ';
  // }
  // cout<<endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define FOR(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
const long long INF = 1e12;
const long long MOD = 1e9 + 7;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];
  // int i=1;
  // int count=1;
  // while(i*=2){
  //     count++;
  //     if(i>1e9){
  //         cout<<count<<endl;
  //         break;
  //     }
  // }
  rep(i, n) {
    int res = 0;
    rep(j, n) {
      if (i == j)
        continue;
      res ^= a[j];
    }
    cout << res << ' ';
  }
  cout << endl;
}