Java O(n*log(n)) binary-search solution with explanation
java\nclass Solution {\n    private static final int MOD = 1000000007;\n    \n    // O(N*LogN)\n    public int waysToSplit(int[] nums) {\n        int[] summary 
```java\nclass Solution {\n    private static final int MOD = 1000000007;\n    \n    // O(N*LogN)\n    public int waysToSplit(int[] nums) {\n        int[] summary = new int[nums.length];\n        int totalSummary = 0;\n        for (int i = 0; i < nums.length; i++) {\n            totalSummary += nums[i];\n            summary[i] = totalSummary;\n        }\n        int ways = 0;\n        // i: right bound of part1\n        for (int i = 0; i < nums.length-2 && summary[i] <= totalSummary/3; i++) {\n            // binary-search\n            int left = summary[i];\n            // find splitIndexMax which part2 \u2264 part3\n            int l = i+1, r = nums.length-2;\n            while (l <= r) {\n                int m = (l+r)>>1;\n                int mTemp = summary[m] - left;         // [i+1, m]\n                int rTemp = totalSummary - summary[m]; // [m+1, nums.length-1]\n                if (mTemp <= rTemp) {\n                    // m, satisfy condition\n                    l = m+1;\n                } else {\n                    r = m-1;\n                }\n            }\n            // if l-1 in [i+1, nums.length-2], it\'s a valid split\n            if (l-1 < i+1 || l-1 > nums.length-2) {\n                continue;\n            }\n            int splitIndexMax = l-1;\n\n            // find splitIndexMin which part1 \u2264 part2\n            l = i+1;\n            r = splitIndexMax;\n            while (l <= r) {\n                int m = (l+r)>>1;\n                int mTemp = summary[m] - left; // [i+1, m]\n                if (mTemp >= left) {\n                    // m, satisfy condition\n                    r = m-1;\n                } else {\n                    l = m+1;\n                }\n            }\n            // if r+1 in [i+1, splitIndexMax], it\'s a valid split\n            if (r+1 < i+1 || r+1 > splitIndexMax) {\n                continue;\n            }\n            int splitIndexMin = r+1;\n            // add to ways and make mod\n            ways += splitIndexMax - splitIndexMin + 1;\n            ways %= MOD;\n        }\n        return ways;\n    }\n}\n```
['Binary Tree', 'Java']