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

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define f(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define pdqueue priority_queue<int, vi, greater<int>>
#define INF 1000000000
#define NINF -1000000000

ll maxll(ll a, ll b) { return a > b ? a : b; }

ll minll(ll a, ll b) { return a > b ? b : a; }

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }

// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }

// int gcd (int a , int b){
//     return __gcd(a,b);
// }

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

void solve() {

  ll n;
  cin >> n;
  vl a(n);
  ll temp = 0;
  f(i, 0, n) {
    cin >> a[i];
    temp ^= a[i];
  }
  ll ans;
  f(i, 0, n) {
    ans = temp ^ a[i];
    cout << ans << " ";
  }

  cout << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);

  int t = 1;
  // cin >> t;

  while (t--) {

    solve();
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define f(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define pdqueue priority_queue<int, vi, greater<int>>
#define INF 1000000000
#define NINF -1000000000

ll maxll(ll a, ll b) { return a > b ? a : b; }

ll minll(ll a, ll b) { return a > b ? b : a; }

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }

// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }

// int gcd (int a , int b){
//     return __gcd(a,b);
// }

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

void solve() {

  ll n;
  cin >> n;
  vl a(n);
  f(i, 0, n) { cin >> a[i]; }
  ll temp;
  f(i, 0, n) {
    temp = 0;
    f(j, 0, n) {
      if (i == j)
        continue;
      temp ^= a[j];
    }
    cout << temp << " ";
  }
  cout << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);

  int t = 1;
  // cin >> t;

  while (t--) {

    solve();
  }
}