如果你WA on #3#4
查看原帖
如果你WA on #3#4
145588
Call_me_Eric楼主2023/10/23 20:53

那你一定是在询问(u,v)(u,v)的最大值时写下了如下代码


int query(int l,int r,int x){
    int u = head2[l - 1], v = head2[r], ans = 0;
    for(int i = 31;i + 1;i--){
        bool opt = (x >> i) & 1;
        if(cnt2[trie2[v][!opt]] - cnt2[trie2[u][!opt]] > 0){opt = !opt;ans += (1 << i);}
        u = trie2[u][opt]; v = trie2[v][opt];
    }
    return ans;
}

其中第二行的head2[l−1]head2[l-1]显然是错的,因为树上的查询是[lca,v]==(falca,v][lca,v] == (fa_{lca},v]而不是简单的lca−1lca-1我不会告诉你因为这个调了好久的

2023/10/23 20:53
加载中...