30pts求调
查看原帖
30pts求调
494539
_String楼主2023/8/24 21:25
#include<cstdio>
#define ll long long
#define rsi register int
int n;
struct P{
	int a,l,r,f;
}p[10000001];
ll xl=0,xr=0;
inline int read(){
	int f=1;
	char ch=getchar();
	while('0'>ch || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	int x=ch^48;
	ch=getchar();
	while('0'<=ch && ch<='9'){
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main(){
//	freopen("Cartesian Tree.in","r",stdin);
//	freopen("Cartesian Tree.out","w",stdout);
	n=read();
	for(rsi i=1;i<=n;++i){
		p[i].a=read();
	}
	p[0].r=1;p[1].l=p[1].r=p[1].f=0;
	for(rsi i=2,j;i<=n;++i){
		j=i-1;
		while(p[i].a<=p[j].a&&j){
			j=p[j].f;
		}
		p[i].l=p[j].r;
		p[p[j].r].f=i;
		p[j].r=i;
		p[i].f=j;
	}
	for(rsi i=1;i<=n;++i){
		xl^=(ll)(i*(p[i].l+1));
		xr^=(ll)(i*(p[i].r+1));
	}
	printf("%lld %lld",xl,xr);
	return 0;
}
2023/8/24 21:25
加载中...