C++ Using Segment Tree(32ms)
Create a Min and Max segment tree. \n- Get min and max for that range and find the arithmatic progression incremental factor. \n- Traverse through the range and
- Create a Min and Max segment tree. \n- Get min and max for that range and find the arithmatic progression incremental factor. \n- Traverse through the range and try finding Index in the Arithmatic progression.\n- Set result to true if we get all unique indexes else set the result to false\n\nT.C : O(mn)\nS.C : O(m)\n\n\n```\nclass Solution {\npublic:\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {\n        int segTreeSize = (nextTwoPower(nums.size()) * 2) -1;\n        vector<int> minSegTree(segTreeSize);\n        vector<int> maxSegTree(segTreeSize);\n        vector<bool> result(l.size());\n        \n        createSumSegTree(minSegTree, maxSegTree, 0, nums.size()-1, 0, nums);\n        \n        for(int i = 0; i<l.size(); i++) {\n            int start = l[i];\n            int end = r[i];\n            if(start == end || start == end-1) {\n                result[i] = true;\n                continue;\n            }\n            \n            int min = querySegTree(minSegTree, 0, nums.size()-1, start, end, 0);\n            int max = querySegTree(maxSegTree, 0, nums.size()-1, start, end, 0, true);\n            \n            if(((max-min)%(end-start)) !=0 ) {\n                result[i] = false;\n                continue;\n            }\n            int ap = (max-min)/(end-start);\n            if(ap == 0) {\n                result[i] = true;\n                continue;\n            }\n            \n            vector<bool> indexCheck(end-start+1, false);\n            bool calculated = false;\n            for(int j = start; j <= end; j++) {\n                if((nums[j]-min) % ap != 0) {\n                    result[i] = false;\n                    calculated = true;\n                    break;\n                }\n                int index = (nums[j]-min)/ap;\n                if(indexCheck[index]) {\n                    result[i] = false;\n                    calculated = true;\n                    break;\n                }\n                indexCheck[index] = true;\n            }\n            if(!calculated) {\n                result[i] = true;\n            }\n        }\n        \n        return result;\n        \n    }\n    \n    void createSumSegTree(vector<int>& minSegTree, vector<int>& maxSegTree, int low, int high, int pos, const vector<int>& input) {\n        if(low == high) {\n            minSegTree[pos] = input[low];\n            maxSegTree[pos] = input[low];\n            return;\n        }\n        \n        int mid = low + (high - low)/2;\n        \n        createSumSegTree(minSegTree, maxSegTree, low, mid, pos*2+1, input);\n        createSumSegTree(minSegTree, maxSegTree, mid+1, high, pos*2 + 2, input);\n        \n        maxSegTree[pos] = std::max(maxSegTree[pos*2+1], maxSegTree[2*pos+2]);\n        minSegTree[pos] = std::min(minSegTree[pos*2+1], minSegTree[2*pos+2]);\n    }\n    \n    int querySegTree(const vector<int>& segTree, int low, int high, int qLow, int qHigh, int pos, bool calMax = false) {\n        // complete overlap\n        if(qLow <= low && qHigh >= high) {\n            return segTree[pos];\n        }\n        // no overlap\n        if(qHigh < low || qLow > high) {\n            if (calMax)\n                return INT_MIN;\n            else return INT_MAX;\n        }\n        \n        int mid = low + (high-low)/2;\n        if (calMax) {\n            return std::max(querySegTree(segTree, low, mid, qLow, qHigh, 2*pos+1, true), querySegTree(segTree, mid+1, high, qLow, qHigh, 2*pos+2, true));\n        }\n        return std::min(querySegTree(segTree, low, mid, qLow, qHigh, 2*pos+1), querySegTree(segTree, mid+1, high, qLow, qHigh, 2*pos+2));\n    }\n    \n    int nextTwoPower(int num) {\n        if(num==0) return 1;\n        \n        if(num>0 && (num & (num-1)) == 0) {\n            return num;\n        }\n        \n        num = num & (num-1);\n        return num << 1;\n    }\n};\n```
[]