#include<bits/stdc++.h>
#define endl '\n'
int n;
struct node {
    int num;
    int index;
};
struct compare {
    bool operator()(node a,node b) {
        return a.num > b.num;
    }
};
std::priority_queue<node,std::vector<node>,compare> que;

using std::cin;
using std::cout;
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    int x;int ans = 0;node goal;
    for(int i = 1;i<=n;i++) {
        cin >> x;
        goal = (node){x,i};
        if(que.empty()) {
            que.push(goal);
            ans^=goal.index;
            cout << ans << endl;
        }
        else {
            while(!que.empty() && que.top().num <= x) {
                ans^=que.top().index;
                que.pop();
            }
            que.push(goal);
            ans^=i;
            cout << ans << endl;
        }
    }
}

题目非常简单,但很坑

坑点解析

1.前缀最大值的按位异或和是索引值,并非实际值

2.ai必须恒大于aj不可以相等,对应代码实现就是que.top().num <= x