笛卡尔树

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e7+10;
struct node{ll ls,rs,fa,pri;}t[N];
ll n;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin >> n;
	stack<ll> sta;sta.push(0);
	for(ll i=1;i<=n;i++){
		cin >> t[i].pri;
		while(t[sta.top()].pri>t[i].pri)sta.pop();
		t[t[i].ls=t[sta.top()].rs].fa=i;
		t[t[sta.top()].rs=i].fa=sta.top();
		sta.push(i);
	}
	ll ans1=0,ans2=0;
	for(ll i=1;i<=n;i++)ans1^=i*(t[i].ls+1),ans2^=i*(t[i].rs+1);
	cout << ans1 << ' ' << ans2;
	return 0;
}
posted @ 2024-01-06 22:36  Alric  阅读(6)  评论(0编辑  收藏  举报