zoukankan      html  css  js  c++  java
  • 笛卡尔树

    笛卡尔树:

    序号满足二分查找树的性质,值满足堆的性质的树。

    构建:

    方法:

    单调栈构建。

    代码:

    const int N = 1e7 + 10;
    
    inline ll Read()
    {
    	ll x = 0, f = 1;
    	char c = getchar();
    	while (c != '-' && (c < '0' || c > '9')) c = getchar();
    	if (c == '-') f = -f, c = getchar();
    	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
    	return x * f;
    }
    
    int n;
    int a[N], ch[N][2];
    int st[N], top;
    ll ansl, ansr;
    int main()
    {
    //	freopen(".in", "r", stdin);
    //	freopen(".out", "w", stdout);
    	n = Read();
    	for (int i = 1; i <= n; i++) a[i] = Read();
    	st[++top] = 0;
    	for (int i = 1; i <= n; i++)
    	{
    		for (; top && a[st[top]] > a[i]; ch[i][0] = st[top--]);
    		if (st[top]) ch[st[top]][1] = i;
    		st[++top] = i;
    	}
    	for (ll i = 1; i <= n; i++) 
    		ansl ^= i * (ch[i][0] + 1), ansr ^= i * (ch[i][1] + 1);
    	printf ("%lld %lld
    ", ansl, ansr);
    	return 0;
    }
    
    
  • 相关阅读:
    css列表
    css字体
    css文本
    css背景
    css里的属性
    MySQL语法大全_自己整理的学习笔记
    必看的 jQuery性能优化的38个建议
    p​h​p​异​常​机​制
    常用软件
    php过滤危险html代码
  • 原文地址:https://www.cnblogs.com/GJY-JURUO/p/15432449.html
Copyright © 2011-2022 走看看