alexjercan/bugnet huggingface dataset:
Problem p02630 (C++) — buggy submission, verdict: Time Limit Exceeded

// I'm a f*cking looser
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<ll>())
#define input(A, N)                                                            \\
  for (ll i = 0; i < N; i++)                                                   \\
    cin >> A[i];
signed main() {
  fasino ll n, q, tmp, k;
  cin >> n;
  vector<ll> A(n);
  input(A, n);
  cin >> q;
  map<ll, ll> mp;
  set<ll> st;
  ll finalsum = 0;
  for (auto i : A) {
    finalsum += i;
    mp[i]++;
  }
  for (int i = 0; i < q; i++) {
    cin >> tmp >> k;
    ll ko = mp[tmp];
    ll ok = mp[k];
    finalsum += ko * k;
    finalsum -= ko * tmp;
    mp[tmp] = 0;
    mp[k] += ko;
    cout << finalsum << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

// I'm a f*cking looser
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<ll>())
#define input(A, N)                                                            \\
  for (ll i = 0; i < N; i++)                                                   \\
    cin >> A[i];
signed main() {
  fasino ll n, q, tmp, k;
  cin >> n;
  vector<ll> A(n);
  input(A, n);
  cin >> q;
  map<ll, ll> mp;
  set<ll> st;
  for (auto i : A) {
    mp[i]++;
    st.insert(i);
  }
  for (int i = 0; i < q; i++) {
    cin >> tmp >> k;
    if (st.find(tmp) != st.end()) {
      mp[k] += mp[tmp];
      mp[tmp] = 0;
      st.insert(k);
      st.erase(tmp);
    }
    ll sum = 0;
    for (auto j : st) {
      sum += mp[j] * j;
    }
    cout << sum << '\\n';
  }
  return 0;
}
Problem p02630 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, 0, n) mp[a[i]]++;
  int q;
  cin >> q;
  ll ans = 0;
  rep(i, 0, n) ans += a[i];
  vector<ll> res;
  rep(i, 0, q) {
    int b, c;
    cin >> b >> c;
    ans -= b * mp[b];
    mp[c] += mp[b];
    ans += c * mp[b];
    mp[b] = 0;
    res.push_back(ans);
  }
  for (ll i : res) {
    cout << i << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, 0, n) mp[a[i]]++;
  int q;
  cin >> q;
  ll ans;
  vector<ll> res;
  rep(i, 0, q) {
    ans = 0;
    int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    for (auto i : mp) {
      ans += i.first * i.second;
    }
    res.push_back(ans);
  }
  for (ll i : res) {
    cout << i << endl;
  }
  return 0;
}
Problem p02630 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
// i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
  i64 n;
  cin >> n;
  vector<i64> as(n);
  map<i64, i64> nums;
  for (int i = 0; i < n; ++i) {
    cin >> as[i];
    auto it = nums.find(as[i]);
    if (it == nums.end())
      nums[as[i]] = 1;
    else
      ++nums[as[i]];
  }
  i64 q;
  cin >> q;

  i64 sum{0};
  for (auto kv : nums) {
    sum += kv.first * kv.second;
  }

  for (int i = 0; i < q; ++i) {
    i64 b, c;
    cin >> b >> c;
    auto it = nums.find(b);
    if (it != nums.end()) {
      auto it2 = nums.find(c);
      if (it2 == nums.end()) {
        nums[c] = it->second;
      } else {
        it2->second += it->second;
      }
      sum += (c - b) * it->second;
      nums.erase(it);
    }
    cout << sum << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
// i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
  i64 n;
  cin >> n;
  vector<i64> as(n);
  map<i64, i64> nums;
  for (int i = 0; i < n; ++i) {
    cin >> as[i];
    auto it = nums.find(as[i]);
    if (it == nums.end())
      nums[as[i]] = 1;
    else
      ++nums[as[i]];
  }
  i64 q;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    i64 b, c;
    cin >> b >> c;
    auto it = nums.find(b);
    if (it != nums.end()) {
      auto it2 = nums.find(c);
      if (it2 == nums.end()) {
        nums[c] = it->second;
      } else {
        it2->second += it->second;
      }
      nums.erase(it);
    }

    i64 sum{0};
    for (auto kv : nums) {
      sum += kv.first * kv.second;
    }
    cout << sum << endl;
  }

  return 0;
}
Problem p02630 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int numberOfElements = 0;
  int numberOfOperations = 0;

  cin >> numberOfElements;
  vector<long long int> arr(numberOfElements);

  long long int sum = 0;

  for (int i = 0; i < numberOfElements; i++) {
    cin >> arr[i];
    sum = sum + arr[i];
  }

  cin >> numberOfOperations;
  vector<vector<int>> op(numberOfOperations, vector<int>(2, 0));

  for (int i = 0; i < numberOfOperations; i++) {
    cin >> op[i][0];
    cin >> op[i][1];
  }

  sort(arr.begin(), arr.end());

  vector<long long> auxiliary(arr[numberOfElements - 1] + 1, 0);
  vector<long long int> output;

  for (int i = 0; i < numberOfElements; i++) {
    auxiliary[arr[i] - 1]++;
  }

  for (int i = 0; i < numberOfOperations; i++) {
    if (auxiliary.size() <= max(op[i][0], op[i][1])) {
      auxiliary.resize(max(op[i][0], op[i][1]) + 1, 0);
    }
    sum = sum + (auxiliary[op[i][0] - 1]) * (op[i][1] - op[i][0]);
    auxiliary[op[i][1] - 1] += auxiliary[op[i][0] - 1];
    auxiliary[op[i][0] - 1] = 0;
    output.push_back(sum);
  }

  for (int i = 0; i < numberOfOperations; i++) {
    cout << output[i] << " ";
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int numberOfElements = 0;
  int numberOfOperations = 0;

  cin >> numberOfElements;
  vector<int> arr(numberOfElements);

  for (int i = 0; i < numberOfElements; i++) {
    cin >> arr[i];
  }

  cin >> numberOfOperations;
  vector<vector<int>> op(numberOfOperations, vector<int>(2, 0));

  for (int i = 0; i < numberOfOperations; i++) {
    cin >> op[i][0];
    cin >> op[i][1];
  }

  sort(arr.begin(), arr.end());

  int sum = 0;

  for (int i = 0; i < numberOfElements; i++) {
    sum = sum + arr[i];
  }

  vector<int> auxiliary(arr[numberOfElements - 1] + 1, 0);
  vector<int> output;

  for (int i = 0; i < numberOfElements; i++) {
    auxiliary[arr[i] - 1]++;
  }

  for (int i = 0; i < numberOfOperations; i++) {
    if (auxiliary[op[i][0] - 1]) {
      if (numberOfElements < op[i][1]) {
        auxiliary.resize(op[i][1], 0);
      }
      sum = sum - (auxiliary[op[i][0] - 1]) * op[i][0] -
            (auxiliary[op[i][1] - 1]) * op[i][1];

      auxiliary[op[i][1] - 1] += auxiliary[op[i][0] - 1];
      sum = sum + (auxiliary[op[i][1] - 1]) * op[i][1];
      output.push_back(sum);
    } else
      output.push_back(sum);
  }

  for (int i = 0; i < numberOfOperations; i++) {
    cout << output[i] << " ";
  }

  return 0;
}
Problem p02630 (C++) — buggy submission, verdict: Runtime Error

/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

void solve(int cnum) {
  int64_t n;
  cin >> n;
  vector<int64_t> arr(n);
  vector<int64_t> freq(100005);
  int64_t sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
    freq[arr[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int64_t a, b;
    cin >> a >> b;
    int64_t num = freq[a];
    int64_t torem = a * num;
    freq[a] = 0;
    sum -= torem;
    torem = b * num;
    sum += torem;
    freq[b] += num;
    cout << sum << "\\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout.tie(nullptr);
  int t;
  int count = 1;
  for (t = 1; t--; solve(count))
    ;
  return 0;
}

Error: 0

Fixed submission:

/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

void solve(int cnum) {
  int64_t n;
  cin >> n;
  vector<int64_t> arr(n);
  vector<int64_t> freq(n);
  int64_t sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
    freq[arr[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int64_t a, b;
    cin >> a >> b;
    int64_t num = freq[a];
    int64_t torem = a * num;
    freq[a] = 0;
    sum -= torem;
    torem = b * num;
    sum += torem;
    freq[b] += num;
    cout << sum << "\\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout.tie(nullptr);
  int t;
  int count = 1;
  for (t = 1; t--; solve(count))
    ;
  return 0;
}
Problem p02630 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target(                                                            \\
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n;
  vector<int> a(200001);
  long long total = 0, temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    total += temp;
    a[temp]++;
  }
  cin >> q;
  vector<pair<int, int>> b(q);
  int num1, num2, ntemp, diff;
  for (int i = 0; i < q; i++) {
    cin >> num1 >> num2;
    diff = num2 - num1;
    total += (a[num1] * diff);
    a[num2] += a[num1];
    a[num1] = 0;
    cout << total << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target(                                                            \\
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<pair<int, int>> b(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i].first >> b[i].second;
  }
  for (int i = 0; i < q; i++) {
    long long sum = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i].first) {
        a[j] = b[i].second;
      }
      sum += a[j];
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02631 (C++) — buggy submission, verdict: Runtime Error

// C++ program to Replace every element
// by the bitwise xor of all other elements
#include <bits/stdc++.h>
using namespace std;

// Function to replace the elements
void ReplaceElements(int arr[], int n) {
  int X = 0;

  // Calculate the xor of all the elements
  for (int i = 0; i < n; ++i) {
    X ^= arr[i];
  }

  // Replace every element by the
  // xor of all other elements
  for (int i = 0; i < n; ++i) {
    arr[i] = X ^ arr[i];
  }
}

// Driver code
int main() {
  int n, i;
  cin >> n;
  int arr[n];
  for (i = 0; i < n; i++)
    cin >> arr[i];

  ReplaceElements(arr, n);

  // Print the modified array.
  for (int i = 0; i < n; ++i) {
    cout << arr[i] << " ";
  }
  return 0;
}


Error: WA

Fixed submission:

/// بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int i, n, t, j = 0, p, x, a = 0, b, l = 0, r = 0, y, k, c, sum = 0, m, d;
  cin >> n;
  x = 0;
  int ara[n];
  for (i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  for (i = 1; i <= n; i++) {
    x = x ^ ara[i] ^ i;
    cout << x << " ";
  }
  return EXIT_SUCCESS;
}
Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)

ll N, xors = 0;
vector<ll> v;
void input() {
  cin >> N;
  v.resize(N);
  for (auto &e : v) {
    cin >> e;
    xors ^= e;
  }
}

void solve() {
  rep(i, 0, N) {
    ll x = 0;
    cout << (xors ^ v[i]);
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)

ll N;
vector<ll> v;
void input() {
  cin >> N;
  v.resize(N);
  for (auto &e : v) {
    cin >> e;
  }
}

void solve() {
  rep(i, 0, N) {
    ll x = 0;
    rep(j, 0, N) {
      if (i == j)
        continue;
      x = x ^ v[j];
    }
    cout << x;
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
}
Problem p02631 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 200010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans;

int a[MAXN];

signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), ans ^= a[i];
  for (int i = 1; i <= n; i++)
    cout << (ans ^ a[i]) << " ";
  puts("");
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 1010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans;

int a[MAXN];

signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), ans ^= a[i];
  for (int i = 1; i <= n; i++)
    cout << (ans ^ a[i]) << " ";
  puts("");
}
Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  unsigned long long int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  unsigned long long int temp;
  temp = A[0];
  for (int i = 1; i < N; i++) {
    temp ^= A[i];
  }
  for (int i = 0; i < N; i++) {
    unsigned long long int tempa = temp ^ A[i];
    cout << tempa << " ";
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  unsigned long long int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    int flag = 0;
    unsigned long long int temp = 0;
    for (int j = 0; j < N; j++) {
      if (j == i)
        continue;
      if (!flag) {
        temp = A[j];
        flag = 1;
      } else {
        temp ^= A[j];
      }
    }
    cout << temp << " ";
  }
}
Problem p02631 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n = 0;
  int x = 0;

  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    t = a[i];
    x = x ^ t;
  }

  for (int i = 0; i < n; i++) {
    a[i] = x ^ a[i];
  }

  cout << a[0];
  for (int i = 1; i < n; i++) {
    cout << " ";
    cout << a[i];
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n = 0;
  int a[n];
  long long x = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = x ^ a[i];
  }
  for (int i = 0; i < n; i++) {
    a[i] = x ^ a[i];
  }

  cout << a[0];
  for (int i = 1; i < n; i++) {
    cout << " " << a[i];
  }
  return 0;
}
Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    res ^= a[i];
  }

  for (int i = 0; i < n; ++i) {
    if (i == n - 1)
      cout << (res ^ a[i]) << endl;
    else
      cout << (res ^ a[i]) << " ";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int res;
  for (int i = 0; i < n; ++i) {
    res = 0;
    for (int j = 0; j < n; ++j) {
      if (j == i)
        continue;
      res ^= a[j];
    }
    if (i == n - 1)
      cout << res << endl;
    else
      cout << res << " ";
  }
}
Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  unsigned int n;

  cin >> n;
  vector<unsigned int> a(n);

  rep(i, n) { cin >> a[i]; }

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

  unsigned int ans;
  rep(i, n) {
    ans = (sum ^ a[i]);

    cout << ans << " ";
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  unsigned int n;

  cin >> n;
  vector<unsigned int> a(n);

  rep(i, n) { cin >> a[i]; }

  unsigned int ans;
  rep(i, n) {
    ans = a[i];
    rep(j, n) { ans = (ans ^ a[j]); }

    cout << ans << " ";
  }
}
Problem p02631 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 2e5 + 5;

const int maxv = 1e9;

int T, tc;
int n;
int a[maxn];

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x ^= a[i];
  }

  for (int i = 0; i < n; i++) {
    printf("%d ", x ^ a[i]);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e5 + 5;

const int maxv = 1e9;

int T, tc;
int n;
int a[maxn];

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x ^= a[i];
  }

  for (int i = 0; i < n; i++) {
    printf("%d ", x ^ a[i]);
  }

  return 0;
}