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

/*
       Hi there <3
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n; i >= a; i--)
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                                                               \\
  {                                                                            \\
    ios::sync_with_stdio(0);                                                   \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define in(x)                                                                  \\
  int x;                                                                       \\
  cin >> x;
#define in1(x)                                                                 \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  x--;
#define inll(x)                                                                \\
  ll x;                                                                        \\
  cin >> x;
#define ins(x)                                                                 \\
  string x;                                                                    \\
  cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve() {
  ll n;
  cin >> n;
  vll v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  int temp = 0;
  for (int i = 0; i < n; i++) {
    temp = temp ^ v[i];
  }
  int final = temp;
  for (int i = 0; i < n; i++) {
    temp = final ^ v[i];
    temp = ~temp;
    temp = temp * -1;
    temp--;
    cout << temp << " ";
  }

  cout << endl;
}

int main() {
  fastIO();
  int t;
  t = 1;
  while (t--) {
    Solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
       Hi there <3
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n; i >= a; i--)
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                                                               \\
  {                                                                            \\
    ios::sync_with_stdio(0);                                                   \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define in(x)                                                                  \\
  int x;                                                                       \\
  cin >> x;
#define in1(x)                                                                 \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  x--;
#define inll(x)                                                                \\
  ll x;                                                                        \\
  cin >> x;
#define ins(x)                                                                 \\
  string x;                                                                    \\
  cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve() {
  ll n;
  cin >> n;
  vll v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  for (int i = 0; i < n; i++) {
    int temp = 0;
    for (int j = 0; j < n; j++) {
      if (j != i) {
        temp = temp ^ v[j];
      }
    }
    temp = ~temp;
    temp = temp * -1;
    temp--;
    cout << temp << " ";
  }
  cout << endl;
}

int main() {
  fastIO();
  int t;
  t = 1;
  while (t--) {
    Solve();
  }
  return 0;
}