关于平板电视(pbds)
  • 板块学术版
  • 楼主MrPython小河狸贝瓦
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/6/21 21:09
  • 上次更新2023/11/3 13:24:20
查看原帖
关于平板电视(pbds)
679581
MrPython小河狸贝瓦楼主2023/6/21 21:09

题目: 【模板】普通平衡树,暂时没有写完

#include<bits/extc++.h>
using namespace std;
namespace pbds=__gnu_pbds;
using ui=unsigned int;
template<typename T,typename compare=less<T>> struct Unique{
    T val;
    size_t id;
    static size_t count;
    Unique(void):val(),id(count++){}
    Unique(T const& x):val(x),id(count++){}
    struct uqCmp{bool operator()(Unique const& x,Unique const& y) const{
        return x.val==y.val?x.id<y.id:x.val<y.val;
    }};
    friend istream& operator>>(istream& in,Unique& x){return in>>x.val;}
    friend ostream& operator<<(ostream& out,Unique const& x){return out<<x.val;}
    operator T(void) const{return val;}
};
template<typename T,typename compare> size_t Unique<T, compare>::count = 0;
template<typename T> using pbds_tree=pbds::tree<Unique<T>,pbds::null_type,typename Unique<T>::uqCmp>;
int main(void){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    size_t n;
    cin>>n;
    pbds_tree<int> tree;
    while (n--){
        char opt;
        cin>>opt;
        switch (opt){
        case '1':{
            int x;
            cin>>x;
            tree.insert(x);
            break;
        }case '2':{
            int x;
            cin>>x;
            pbds_tree<int>::iterator it=tree.lower_bound(x);
            if (*it==x) tree.erase(it);
            break;
        }case '3':{
            int x;
            cin>>x;
            cout<<tree.order_of_key(x)+1<<'\n';
            break;
        }case '4':{
            size_t x;
            cin>>x;
            pbds_tree<int>::iterator it=tree.find_by_order(x);
            if (it!=tree.end()) cout<<*it<<'\n';
            break;
        }
        }
    }
    return 0;
}

Luogu IDE 报错:

/tmp/compiler_ohv7x9s8/src: 在函数‘int main()’中:
/tmp/compiler_ohv7x9s8/src:43:24: 错误:‘pbds_tree<int>’ {aka ‘class __gnu_pbds::tree<Unique<int, std::less<int> >, __gnu_pbds::null_type, Unique<int, std::less<int> >::uqCmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::null_node_update, std::allocator<char> >’} has no member named ‘order_of_key’
   43 |             cout<<tree.order_of_key(x)+1<<'\n';
      |                        ^~~~~~~~~~~~
/tmp/compiler_ohv7x9s8/src:48:46: 错误:‘pbds_tree<int>’ {aka ‘class __gnu_pbds::tree<Unique<int, std::less<int> >, __gnu_pbds::null_type, Unique<int, std::less<int> >::uqCmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::null_node_update, std::allocator<char> >’} has no member named ‘find_by_order’
   48 |             pbds_tree<int>::iterator it=tree.find_by_order(x);
      |                                              ^~~~~~~~~~~~~
2023/6/21 21:09
加载中...