O(log(n)) Binary Search Beats 100% C++ 32 Line
\nclass RLEIterator {\npublic:\n    RLEIterator(vector<int> A) {// O(n) time \n\t\tloc=0;\n        sum=0;\n\t\tcnt.push_back(0);\n\t\tnum.push_back(-1); \n\t\tf
```\nclass RLEIterator {\npublic:\n    RLEIterator(vector<int> A) {// O(n) time \n\t\tloc=0;\n        sum=0;\n\t\tcnt.push_back(0);\n\t\tnum.push_back(-1); \n\t\tfor( int i=0; i<A.size(); i+=2){\n\t\t\tcnt.push_back(cnt.back()+A[i]); \n\t\t\tnum.push_back(A[i+1]); \n\t\t}\n    }\n    \n    int next(int n) {// O(log(n)) time\n\t\tsum+=n;\n\t\tif(cnt.back()<sum)\treturn -1;\n\t\tint b=loc, e=cnt.size()-1, mid;// (b,e]\n\t\twhile(b+1<e){\n\t\t\tmid=b+(e-b)/2;\n\t\t\tif(cnt[mid]<sum)\tb=mid;\n\t\t\telse\te=mid;\n\t\t}\n\t\tloc=b;// update begining point to speed up binary search \n\t\treturn num[e];\n    }\n\t\nprotected:\n\tint loc;// current location \n\tlong sum;// total count \n\tvector<long> cnt;// count \n\tvector<int> num;// number value \n};\n```
[]