class Solution {
HashMap map = new HashMap();
Random ra = new Random(300);
int m, n, cnt;
public Solution(int m, int n) {
this.m = m;
this.n = n;
this.cnt = m * n;
}
public int[] flip() {
//在[0,cnt)取一个随机数,并给右边界-1
int x = ra.nextInt(cnt--);
int idx = map.getOrDefault(x, x);
map.put(x, map.getOrDefault(cnt, cnt));
return new int[] { idx / n, idx % n };
}
public void reset() {
cnt = m * n;
map.clear();
}
}



