binary search save the space as good as the tricky way!
\n\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> fliped;//x+m*y,x0m-1,y0n-1.\n    int m,n;\n    Solution(int m, int n): m{m},n{n}{\n    }\n    \n    v
![image.png](https://assets.leetcode.com/users/images/9482aa4f-27b7-4e91-a56a-a6f5e365b0e0_1720387771.0202808.png)\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> fliped;//x+m*y,x0m-1,y0n-1.\n    int m,n;\n    Solution(int m, int n): m{m},n{n}{\n    }\n    \n    vector<int> flip() {\n        while(true){\n            int seed=rand()%(m*n);\n            auto it = lower_bound(fliped.begin(),fliped.end(),seed);\n            if(it == fliped.end() || *it>seed){\n                fliped.insert(it,seed);\n                return {seed%m,seed/m};\n            }\n        }\n    }\n    \n    void reset() {\n        fliped={};\n    }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(m, n);\n * vector<int> param_1 = obj->flip();\n * obj->reset();\n */\n```
['C++']