結果

問題 No.686 Uncertain LIS
ユーザー xxyPertaxxyPerta
提出日時 2023-12-31 18:06:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,752 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 169,432 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2023-12-31 18:06:33
合計ジャッジ時間 8,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 125 ms
8,768 KB
testcase_10 AC 118 ms
8,768 KB
testcase_11 AC 70 ms
8,512 KB
testcase_12 AC 5 ms
6,548 KB
testcase_13 AC 32 ms
6,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 150 ms
8,896 KB
testcase_19 AC 152 ms
8,896 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 66 ms
8,564 KB
testcase_25 AC 66 ms
8,600 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
const int N=6e5+10;
int n,ans,cnt,root;
int Fa[N],num[N],son[N][2],tag[N];
inline void Max(int &x,int y) {x=x>y?x:y;}
bool loc(int x) {return son[Fa[x]][1]==x;}
void inc(int x)
{
	if(!tag[x]||!x) return;
    num[son[x][0]]+=tag[x];
	tag[son[x][0]]+=tag[x];
    num[son[x][1]]+=tag[x];
	tag[son[x][1]]+=tag[x];
	tag[x]=0;
}
void rot(int x)
{
	int fa=Fa[x],ffa=Fa[fa],L=loc(x);
	inc(x),inc(fa);
    son[fa][L]=son[x][L^1];
    Fa[son[fa][L]]=fa;
	if(ffa) son[ffa][loc(fa)]=x;
	Fa[fa]=x;
	Fa[x]=ffa;
    son[x][L^1]=fa;
}
void splay(int x,int up)
{
	for(int fa;(fa=Fa[x])!=up;rot(x))
        if(Fa[fa]!=up) rot(loc(x)==loc(fa)?fa:x);
	if(!up) root=x;
}
int pree(int x)
{
    int now=root,res=-1;
    while(now)
    {
        inc(now);
        if(num[now]<x) res=now,now=son[now][1];
        else now=son[now][0];
    }
    return res;
}
int suff(int x)
{
	int now=root,res=-1;
	while(now)
	{
		inc(now);
        if(num[now]>=x) res=now,now=son[now][0];
		else now=son[now][1];
	}
    return res;
}
void add(int x)
{
    int ned=suff(x);
    if(!~ned)
    {
        ned=pree(x);
        assert(~ned);
        splay(ned,0);
        inc(ned);
        Fa[++cnt]=ned,num[cnt]=x,son[cnt][1]=son[ned][1];
        Fa[son[ned][1]]=cnt;
        son[ned][1]=cnt;
        splay(cnt,0);
        return;
    }
    splay(ned,0);
    inc(ned);
    Fa[++cnt]=ned,num[cnt]=x,son[cnt][0]=son[ned][0];
    Fa[son[ned][0]]=cnt;
    son[ned][0]=cnt;
    splay(cnt,0);
}
void del(int x)
{
    while(1)
        if(son[x][0]) rot(son[x][0]);
        else if(son[x][1]) rot(son[x][1]);
        else break;
    son[Fa[x]][loc(x)]=0;
    splay(Fa[x],0);
}
void dfs(int x)
{
    ++ans;
    if(son[x][0]) dfs(son[x][0]);
    if(son[x][1]) dfs(son[x][1]);
}
int main()
{
    n=read();
    cnt=root=1;
    for(int i=1,l,r;i<=n;i++)
    {
        l=read(),r=read();
        if(i==1) {num[1]=l;continue;}
        int suf=suff(r),ned=pree(l);
        if(~suf&&~ned)
        {
            splay(suf,0);
            splay(ned,suf);
            num[son[ned][1]]++;
            tag[son[ned][1]]++;
        }
        else if(~suf)
        {
            splay(suf,0);
            num[son[suf][1]]++;
            tag[son[suf][1]]++;
        }
        else if(~ned)
        {
            splay(ned,0);
            num[son[ned][1]]++;
            tag[son[ned][1]]++;
        }
        else
        {
            num[root]++;
            tag[root]++;
        }
        add(l);
        if(~suf) del(suf);
        num[0]=tag[0]=0;
    }
    dfs(root);
    printf("%d\n",ans);
    return 0;
}
0