QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460543#4894. 学姐买瓜Bronya0 2ms6024kbC++142.2kb2024-07-01 20:15:232024-07-01 20:15:24

Judging History

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

  • [2024-07-01 20:15:24]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:6024kb
  • [2024-07-01 20:15:23]
  • 提交

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]=0;
    update(x);
}
void link(int x,int y){
    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;
    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;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 6020kb

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:

0
1
2
1
3

result:

ok 5 lines

Test #2:

score: -20
Wrong Answer
time: 2ms
memory: 6024kb

input:

2000 2000
2 66 273
1 475 1570
2 51 958
2 731 1771
1 1286 1627
1 37 892
1 529 890
2 155 1486
1 87 1815
1 576 1872
2 1269 1515
2 1521 1794
2 634 1887
2 204 1668
1 351 1679
2 1571 1599
1 243 681
2 1 2000
2 1 2000
2 564 648
2 1215 1807
2 466 1617
1 1119 1348
1 497 886
2 1358 1487
2 173 1974
1 401 1294
2...

output:

0
0
0
1
0
0
1
2
0
2
2
0
1
1
0
2
1
1
0
1
0
1
0
0
1
2
1
1
1
2
1
1
0
0
2
2
0
2
2
0
1
3
0
0
4
0
0
2
2
5
2
0
4
0
2
0
2
3
3
0
0
1
3
2
0
3
6
1
0
1
2
4
0
8
0
8
1
3
1
8
1
4
9
3
3
0
7
6
2
9
5
0
9
1
4
8
9
1
0
8
0
9
7
9
2
3
0
6
10
4
6
0
1
0
6
4
6
5
4
6
4
3
10
0
6
2
8
9
1
10
5
7
8
10
8
10
8
6
2
6
1
5
10
8
10
5
3...

result:

wrong answer 71st lines differ - expected: '1', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%