QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460554#4894. 学姐买瓜Bronya0 0ms0kbC++142.3kb2024-07-01 20:30:082024-07-01 20:30:09

Judging History

你现在查看的是最新测评结果

  • [2024-07-01 20:30:09]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-07-01 20:30:08]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
int n,m;
struct LCT{
    int son[2],fa;
    int val;
    int sum;
}t[300005];
bool check(int x){
    return (t[t[x].fa].son[0]==x||t[t[x].fa].son[1]==x);
}
void update(int x){
    t[x].sum=t[x].val+t[t[x].son[0]].sum+t[t[x].son[1]].sum;
}
void rotate(int x){
    int y=t[x].fa,z=t[y].fa;
    if(check(y)){
        if(t[z].son[0]==y)t[z].son[0]=x;
        else t[z].son[1]=x;
    }
    bool pd=(t[y].son[1]==x);
    t[y].son[pd]=t[x].son[pd^1];
    if(t[x].son[pd^1])t[t[x].son[pd^1]].fa=y;
    t[x].son[pd^1]=y;
    t[y].fa=x;t[x].fa=z;
    update(y);update(x);
}
int fa[300005];
void Splay(int x){
    while(check(x)){
        int y=t[x].fa;
        if(check(y)){
            int z=t[y].fa;
            if((t[y].son[0]==x)^(t[z].son[0]==y))rotate(x);
            else rotate(y);
        }
        rotate(x);
    }
    return;
}
void access(int x){
    int y=0;
    while(x){
        Splay(x);
        t[x].son[1]=y;update(x);
        y=x;x=t[x].fa;
    }
}
set<pair<int,int> >st;
void cut(int x){
    access(x);
    Splay(x);
    int y=t[x].son[0];
    t[x].son[0]=t[y].fa=0;t[x].val=0;
    t[x].fa=x+1;fa[x]=x+1;
    update(x);
}
void link(int x,int y){
    assert(t[x].son[0]==0);assert(t[x].fa==0);
    Splay(x);t[x].fa=y;fa[x]=y;t[x].val=1;
    update(x);
}
void Insert(int l,int r){
    st.insert({r,l});
    auto it=st.find({r,l});
    if(it!=st.begin()&&prev(it)->second>=l){
        st.erase(it);
        return;
    }
    it++;
    while(it!=st.end()&&it->second<=l){
        cut(it->second);
        st.erase(it++);
    }
    cut(l);link(l,r+1);
}
int Find(int x,int lim){
    int sum=0;
    if(fa[x]<=lim){
        sum=t[x].val+t[t[x].son[1]].sum;
        if(t[x].son[0])sum+=Find(t[x].son[0],lim);
        else Splay(x);
    }
    else {
        if(t[x].son[1])sum+=Find(t[x].son[1],lim);
        else Splay(x);
    }
    return sum;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m+1;i++)t[i].fa=i+1,fa[i]=i+1;
    fa[m+1]=m+2;
    for(int i=1;i<=n;i++){
        int op,l,r;
        scanf("%d%d%d",&op,&l,&r);
        if(op==1)Insert(l,r);
        else {
            access(l);Splay(l);
            printf("%d\n",Find(l,r+1));
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

11 13
2 4 4
1 11 12
1 1 5
1 2 3
1 2 10
2 2 8
1 6 6
2 2 10
1 6 11
2 2 3
2 2 13

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%