Vague output in codeforces!

Revision en2, by aaditya7739008423, 2022-12-28 18:34:11

Can anyone tell me why this code is giving wrong output in the following question while submitting but giving correct in other compilers? Thank you

#include <bits/stdc++.h>

#include <unordered_map>

#pragma GCC optimize("O2")

using namespace std;

#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define testcase     \
    long long testn; \
    cin >> testn;    \
    while (testn--)


void solve() {
    int n;
    cin >> n;
    vector<int> arr(n), squares = {0, 1};
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i < n; i++) {
        arr[i] = arr[i - 1] ^ arr[i];
    }
    for (int i = 2; i < 2 * n; i++) {
        if (sqrt(i) * sqrt(i) == i) squares.push_back(i);
    }
    int total = 0;
    for (auto& curr : squares) {
        int ans = 0;
        unordered_map<int, int> m;
        m[0] = 1;
        for (int i = 0; i < n; i++) {
            ans += m[curr ^ arr[i]];
            m[arr[i]]++;
        }
        total += ans;
    }
    cout << ((long long)(n * (n + 1)) / 2) - total << endl;
}
int main() {
    IOS;

    testcase {
        solve();
    }
    return 0;
}

Question Link: https://mirror.codeforces.com/contest/1731/problem/C My output 4 11 0 20 When I submit this is the output in test case 1: 4 6 0 12

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English aaditya7739008423 2022-12-28 18:34:11 1 Tiny change: 'est case 1\n4\n6\n0\' -> 'est case 1:\n4\n6\n0\'
en1 English aaditya7739008423 2022-12-28 18:33:47 1457 Initial revision (published)