本文整理汇总了C++中Treap类的典型用法代码示例。如果您正苦于以下问题:C++ Treap类的具体用法?C++ Treap怎么用?C++ Treap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Treap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forn
forn(q,Q)
{
char op[8];
scanf("%s", op);
if (op[0] == 'I')
{
int x,y;
scanf("%d%d", &x,&y);
x--;
// Esto es parecido (pero bien diferente :P) al codigo de insertarAUnladoPointer, pero empezando en p en lugar de en root
// De entrada me comi que era hacer lo mismo exacto que insertarAUnLado, y pegue WA.
// Y luego me comi otro WA por olvidarme la linea p = p->h(0); :P
// Moraleja: esto seria bastante mas error prone que el split obvio.
Nodo<Datos> *p = iesimo(x, t), *nodo = new Nodo<Datos>(y);
int lado = 0;
if (p->h(0))
{
p = p->h(0);
lado = 1;
while (p->h(1)) p = p->h(1);
}
p->hang(lado, nodo);
nodo->flotar();
t.reroot();
}
else if (op[0] == 'D')
{
int x;
scanf("%d", &x);
x--;
t.erasePointer(iesimo(x, t));
}
else if (op[0] == 'R')
{
int x,y;
scanf("%d%d", &x, &y);
x--;
Nodo<Datos> *p = iesimo(x, t);
p->dat.x = y;
p->fullUpdate();
}
else if (op[0] == 'Q')
{
int x,y;
scanf("%d%d", &x,&y);
x--;
assert(x < y);
Treap<Datos> t2,t3;
t.splitPointer(iesimo(x, t), t2);
t2.splitPointer(iesimo(y-x, t2), t3);
printf("%d\n", t2.root->dat.bestSum);
t.merge(t2);
t.merge(t3);
}
else
assert(false);
}
示例2: update
Treap *left_rotate() {
Treap *y = left;
left = y->right;
y->right = this;
update();
y->update();
return y;
}
示例3: treap
void treap()
{
Treap<int> treap;
#define TREAP_LOOP for (int i = 0; i < 1000; i ++)
TREAP_LOOP
{
treap.Insert(i);
assert(treap.GetMin() == 0);
assert(treap.GetMax() == i);
}
std::cout<<"Treap constructed"<<std::endl;
// print keys in sorted order
treap.InOrderTraversal();
TREAP_LOOP
{
assert(treap.Exists(i));
}
TREAP_LOOP
{
treap.Delete(i);
}
TREAP_LOOP
{
assert(!treap.Exists(i));
}
}
示例4: main
int main()
{
int a[] = {4,1,3,5,2};
Treap bst = Treap();
for (int i=0; i<5; i++)
{
pair< Treap, Treap > splitedTreap = bst.SplitByVal(a[i]);
Treap singleNodeTreap = Treap(a[i], 1);
bst = splitedTreap.X.Join(singleNodeTreap);
bst = bst.Join(splitedTreap.Y);
}
bst.Print();
return 0;
}
示例5: main
int main()
{
Tree<int> tree;
Treap<int> treap;
int n = 0;
cin >> n;
int value = 0;
int priority = 0;
for(int i = 0; i < n; i++) {
cin >> value >> priority;
tree.Add(value);
treap.Add(value, priority);
}
cout << tree.Height() - treap.Height();
return 0;
}
示例6: main
int main()
{
freopen("Text/ORDERSET.txt","r",stdin);
int Q; scanf("%d",&Q);
Treap oTreap;
while(Q--)
{
char t[5];
int p;
scanf("%s%d",t,&p);
if(t[0]=='I')
{
oTreap.Insert(p);
}
else if(t[0]=='D')
{
oTreap.Delete(p);
}
else if(t[0]=='K')
{
int v = oTreap.FindKth(p);
if(v > -INF)
{
printf("%d\n",v);
}
else
puts("invalid");
}
else
{
int v = oTreap.Count(p);
printf("%d\n",v);
}
}
return 0;
}
示例7: TEST
TEST(Treap , Remove)
{
Treap* tr = new Treap(false);
size_t n=5000;
uint32_t* A = (uint32_t*)malloc(n*sizeof(uint32_t));
for (size_t i=0; i<n; i++) A[i] = rand() % 5001;
for (size_t i=0; i<n; i++) tr->Insert(A[i]);
for (size_t i=1; i<n; i+=2) tr->Remove(A[i]);
for (size_t i=0; i<n; i++) {
if (i%2==1) {
CHECK(tr->Find(A[i]) == false);
}
}
free(A);
delete tr;
}
示例8: main
int main()
{
try {
Treap<int> tr;
tr.push(3);
tr.push(2);
tr.push(5);
tr.push(7);
tr.print();
tr.remove(2);
cout << "\n";
tr.print();
return 0;
}
catch(const reaper::error_base &e) {
cout << e.what() << endl;
return 1;
}
}
示例9: main
int main(){
//freopen("My/4554/9.dat", "r", stdin);
Treap * treap = new Treap();
int n, a, b, type;
char c;
scanf("%d", &n);
for( int i=1; i<=n; i++ ){
scanf("%d %d %d", &type, &a, &b);
bool res;
if( type == 1 ){
scanf(" %c", &c);
res = treap->insert( a, b - 1, c );
} else {
res = treap->erase( a, b - 1 );
}
if( res ){
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
示例10: solve
void solve(){
int N,X;
char ch[5];
scanf("%d",&N);
Treap root;
while(N--){
scanf("%s%d",ch,&X);
if (ch[0] == 'I')
root.Insert_unq(X);//, root.print();
else if (ch[0] == 'D')
root.Erase(X);
else if (ch[0] == 'C'){
int res = root.Count(X);
printf("%d\n",res);
} else {
int res = root.Kth(X);
if (res == INT_MIN)
printf("invalid\n");
else
printf("%d\n",res);
}
}
}
示例11: main
int main()
{
size_t elementsNumber = 0;
cin >> elementsNumber;
if ( elementsNumber == 0 )
{
return 1;
}
BinaryTree binaryTree;
Treap treap;
for ( size_t i = 0; i < elementsNumber; ++i )
{
int k = 0;
int p = 0;
cin >> k >> p;
binaryTree.Add( k );
treap.Add( k, p );
}
const int result = (int)treap.GetWidestLayer() - (int)binaryTree.GetWidestLayer();
cout << result;
return 0;
}
示例12: Menu
void Menu()
{
int val,choice,newVal;
Treap myTreap;
while(true)
{
do
{
cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
cout<<" 1.插入"<<endl;
cout<<" 2.删除"<<endl;
cout<<" 3.修改"<<endl;
cout<<" 4.查找"<<endl;
cout<<" 5.显示"<<endl;
cout<<" 6.返回"<<endl;
cout<<"请输入你的选项[ ]\b\b";
cin>>choice;
}while(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=5&&choice!=6);
if(1==choice)
{
cin>>val;
myTreap.InsertTreap(val);
}
else if(2==choice)
示例13: main
int main() {
srand(time(0));
const int MAX = 1000;
Treap<int, int> treap;
for (int i = 0; i < MAX; i++) {
assert(treap.add(i, i));
}
for (int i = 0; i < MAX; i++) {
assert(treap.contains(i));
}
assert(treap.contains(MAX+1) == false);
assert(treap.remove(7));
assert(treap.contains(7) == false);
std::cout << "Finished succesfully." << std::endl;
return 0;
}
示例14: rank
int rank(int v)
{
int ans;
if (v<=tra.size()) //at top area
{
ans=rm[MAX-1-tra.find_kth(v)];
}
else
{
if (tra.size()==0)
ans=v;
else
{
v-=tra.size();
int lo=1,hi=n,mid;
while (lo<=hi)
{
mid=(lo+hi)/2;
int tmp=mid-trb.rank(mid);
if (tmp>=v)
hi=mid-1;
else
lo=mid+1;
}
ans=lo;
}
}
return ans;
}
示例15: main
int main() {
int n, low;
srand(time(0));
while (EOF != scanf("%d%d", &n, &low)) {
int k;
char s[4];
tr.init();
while (n--) {
scanf("%s%d", s, &k);
if (s[0] == 'I') {
if (k >= low) {
tr.insert(k);
} else {
// tr.del_cnt++;
// 傻逼了,公司都没进,哪来的出公司啊
}
} else if (s[0] == 'A') {
tr.delta += k;
} else if (s[0] == 'S') {
tr.delta -= k;
tr.del_low(low);
} else if (s[0] == 'F') {
printf("%d\n", tr.find_kth(tr.size() - k + 1));
} else {
for(;;);
}
}
printf("%d\n", tr.del_cnt);
}
return 0;
}