关于set
  • 板块学术版
  • 楼主02Ljh
  • 当前回复6
  • 已保存回复7
  • 发布时间2024/8/13 10:11
  • 上次更新2024/8/13 11:58:48
查看原帖
关于set
578004
02Ljh楼主2024/8/13 10:11

定义了一个双关键字的 multiset,按双关键字升序排序,但如果集合中没有第一关键字为 aa 的元素,我对其二分找 a,−1{a,-1} 时他却返回了一个形如 a,0{a,0} 的元素

(语文太差了描述不清问题,具体看代码)

struct pr1
{
    int c,v; 
    friend bool operator<(pr1 x,pr1 y)
    {
        if(x.c==y.c) return x.v<y.v;
        return x.c<y.c;
    }
};
multiset<pr1> s1[100];
int main()
{
    int p=1;s1[p].clear(); s1[p].insert(pr1{1,36254}); s1[p].insert(pr1{1,532100});
    auto kk=s1[p].lower_bound(pr1{2,-1});
    //no 2 appeared
    cout<<kk->c<<" "<<kk->v<<"\n";
    //but the output is {2,0}
    return 0;
}

这段代码输出为 2,0{2,0},但该集合中并没有这个元素

2024/8/13 10:11
加载中...