QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460555#4894. 学姐买瓜Bronya0 2ms3828kbC++142.3kb2024-07-01 20:31:362024-07-01 20:31:37

Judging History

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

  • [2024-07-01 20:31:37]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3828kb
  • [2024-07-01 20:31:36]
  • 提交

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==x+1);
    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
Wrong Answer

Test #1:

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

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
Accepted
time: 2ms
memory: 3828kb

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
1
4
0
8
0
8
1
3
1
8
1
4
9
2
2
0
4
5
2
9
3
0
9
1
3
8
9
1
0
7
0
8
5
7
0
1
0
6
10
2
6
0
1
0
6
4
6
5
4
4
4
0
10
0
6
2
8
9
1
10
5
7
8
10
1
10
8
5
2
6
1
5
10
8
10
5
3...

result:

ok 1020 lines

Test #3:

score: 20
Accepted
time: 2ms
memory: 3828kb

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
1
4
0
8
0
8
1
3
1
8
1
4
9
2
2
0
4
5
2
9
3
0
9
1
3
8
9
1
0
7
0
8
5
7
0
1
0
6
10
2
6
0
1
0
6
4
6
5
4
4
4
0
10
0
6
2
8
9
1
10
5
7
8
10
1
10
8
5
2
6
1
5
10
8
10
5
3...

result:

ok 1020 lines

Test #4:

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

input:

14 11
1 1 8
1 4 11
2 4 8
1 2 7
1 7 11
2 2 9
1 6 10
1 2 6
1 8 10
1 2 6
2 9 10
1 9 9
1 3 10
1 2 4

output:

0
1
0

result:

ok 3 lines

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 3752kb

input:

2000 2000
1 1589 1640
1 1741 1765
2 191 1596
1 426 493
2 1434 1606
1 925 955
2 589 1148
2 1347 1608
2 686 1516
1 1535 1563
1 1835 1841
1 1513 1537
2 30 1710
2 123 171
2 1 2000
2 128 1310
2 270 879
1 1918 1941
2 965 1951
2 176 1452
1 1391 1421
1 614 664
2 1 2000
1 296 328
1 1378 1402
1 29 47
1 92 123...

output:

0
0
1
0
1
4
0
6
6
6
5
7
9
12
10
10
7
14
11
7
7
7
13
10
10
19
14
20
1
4
3
10
1
5
4
8
3
5
24
18
16
17
13
0
28
22
4
6
13
1
13
4
15
6
2
16
1
33
25
18
18
17
8
17
23
36
22
27
34
24
9
7
17
2
12
16
39
22
32
40
4
10
15
23
21
14
10
15
6
43
36
4
17
0
1
15
14
29
33
8
44
44
5
12
27
22
11
6
23
0
7
33
22
41
1
11
3...

result:

wrong answer 9th lines differ - expected: '2', found: '6'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%