Simple O(n) Approach


#1
int Solution::solve(vector<int> &A) {
    int n=A.size();
    int ans=0;
    for(int i=1;i<=n;i++){
        int total_occ=n+((i-1)*(n-i));
        if(total_occ&1) ans^=A[i-1];
    }
    return ans;
}