aaditya7739008423's blog

By aaditya7739008423, history, 16 months ago, In English

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://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

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it