SG函数:https://ac.nowcoder.com/acm/contest/5531/F
题解链接:https://ac.nowcoder.com/discuss/424000?type=101&order=0&pos=34&page=1