C++ solution in O(N), using cumulative sum and binary search
```` class Solution { public:     vector threeEqualParts(vector& A) {               int ones = 0;         vector B = A;         for (int i = 0; i < A.size(); i+
````
class Solution {
public:
    vector<int> threeEqualParts(vector<int>& A) {        
        int ones = 0;
        vector<int> B = A;
        for (int i = 0; i < A.size(); i++)
            ones += A[i];
        
        if (ones == 0) {
            return {0, 2};
        }
        else {
            if (ones % 3 != 0) {
                return {-1, -1};
            }
            else {
                ones /= 3;
                
                // Count the number of trailing zeros in part 3
                int z3 = 0;
                for (int i = A.size() - 1; A[i] == 0; i--)
                    z3++;
                
                // Cumulate
                for (int i = 1; i < A.size(); i++)
                    A[i] += A[i-1];
                
                int p1 = lower_bound(A.begin(), A.end(), ones) - A.begin();
                if (A[p1 + z3] != ones)
                    return {-1, -1};
                
                int p2 = lower_bound(A.begin(), A.end(), 2 * ones) - A.begin();
                if (A[p2 + z3] != 2 * ones)
                    return {-1, -1};
                
                // Check the content of the 3 arrays
                int L = A.size() - 1;
                bool ok = true;
                for (int i = 0; ones && ok; i++) {
                    ok &= B[L - i] == B[p2 + z3 - i];
                    ok &= B[L - i] == B[p1 + z3 - i];
                    ones -= B[L - i];
                }
                
                if (ok)
                    return {p1 + z3, p2 + z3 + 1};
                else
                    return {-1, -1};
            }
        }
    }
};
````

[]