C++ solution using sort and power modulation
\nclass Solution \n{\n    public:\n    long powmod(long a,long b,long d)\n    {\n        long result=1,base=a;\n        while(b)\n        {\n            if(b&1)
```\nclass Solution \n{\n    public:\n    long powmod(long a,long b,long d)\n    {\n        long result=1,base=a;\n        while(b)\n        {\n            if(b&1) result=(result*base)%d;\n            base=(base*base)%d;\n            b>>=1;\n        }\n        return result;\n    }\n    int countWays(vector<vector<int>>& ranges) \n    {\n        sort(ranges.begin(),ranges.end());\n        long d=1000000007,n=ranges.size(),last=ranges[0][1],c=1;\n        for(int i=0;i<n;i++)\n            if(ranges[i][0]<=last) last=max(last,1l*ranges[i][1]);\n            else c++,last=ranges[i][1];\n\n        return powmod(2,c,d);\n    }\n};\n```
[]