Exemplo n.º 1
0
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));
	}
}
Exemplo n.º 2
0
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;
}