前者不开O2时谨慎使用!
后者尽量不要用!
STL库介绍比较多,其中字符串库用的比较少但也应该记住
http://www.cnblogs.com/rvalue/p/7276883.html
http://www.cnblogs.com/rvalue/p/7327293.html
pb_ds差别不大,但这两个库最大的缺陷就是几乎无法用gdb调试,只能手工输出
下面这个程序运行出来之后就是个小教程
#include<cstdio> #include<vector> #include<ext/pb_ds/priority_queue.hpp> #include<ext/pb_ds/assoc_container.hpp> struct Cmp{ int operator() (const int &a,const int &b) { return a>b; } }; using namespace std; using namespace __gnu_pbds; typedef __gnu_pbds::priority_queue<int,Cmp,pairing_heap_tag > Que; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Tree; Que a,d; Que::point_iterator p=a.push(0); Tree b,c; Tree::const_iterator it; int main(){ puts(""); puts("---------using namespace __gnu_pbds---------"); puts(""); puts("---Include<ext/pb_ds/assoc_container.hpp> for ‘tree‘---"); puts(""); it=b.insert(200).first; puts("Insert(int x) returns pair<iterator,bool>"); printf("b.insert(200).first:%d\\n\\n",*it); b.insert(100); puts("Find_by_order(int x) returns the x+1 least element const_iterator"); printf("b(100,200).find_by_order(1):%d\\n\\n",*b.find_by_order(1)); puts("Order_of_key(int x) returns the rank-1 of element‘x‘"); printf("b(100,200).order_of_key(100):%d\\n\\n",b.order_of_key(100)); b.split(100,c); puts("Split(int key,Tree C)clear C at first,and move the element larger than key into C"); printf("b(100,200).split(100,c), c.begin():%d\\n\\n",*c.begin()); puts("---Include<.../priority_queue.hpp> for ‘priority_queue‘---"); puts(""); puts("push(int x) returns the inserted point_iterator"); printf("a.push(0) , *p=*a.push(0):%d\\n\\n",*p); a.push(1); a.push(3); a.modify(p,2); puts("Modify(iterator,int) change the value of (*p),this heap is maintained automatically"); printf("a.modify(p,2) , *p:%d\\n\\n",*p); a.erase(p); puts("Erase(iterator) delete this element,this iterator dies"); printf("a.erase(p) , a.top():%d\\n",a.top()); a.pop(); printf("a.pop() , a.top():%d\\n\\n",a.top()); d.push(-1); a.join(d); puts("a.join(d) join d into a , and then maintain a,clear d"); printf("d.push(-1) , a.join(d) ,a.top():%d\\n\\n",a.top()); puts("----Other functions are not normally used in contests----"); return 0; }
三份比较好的教程
https://gitee.com/HocRiser/templates/blob/master/Others/C_ext_pb_ds_1.pdf
https://gitee.com/HocRiser/templates/blob/master/Others/C_ext_pb_ds_2.pdf
https://gitee.com/HocRiser/templates/blob/master/Others/STL.pdf
没有这方面的例题,万不得已的时候才会用
上面有篇文章中说经测试一般不慢于STL库,但实测有不少情况下常数有STL的三倍之多。
且考场上是否允许使用仍有争议(NOI2017现场有人用没出事但不代表其他考试一定没事)