Cod sursa(job #771000)

Utilizator veleanduAlex Velea veleandu Data 24 iulie 2012 15:44:40
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define maxn 1000000

    ifstream in("hashuri.in");
    ofstream out("hashuri.out");

    typedef struct { long val; char tip; } query;
    query T[maxn];
    long n,i,j;
    long Sn[maxn],l;
    bool V[maxn];

long b_search ( long val )
{
    long ind=0,rez=1;
    for ( ind=1; ind<=l; ind<<=1 )
        ;
    for ( ; ind; ind>>=1 )
        if (( ind+rez <= l) && ( Sn[ind+rez]<=val ))
            rez+=ind;
    return rez;
}

int main()
{
    in>>n;
    for ( i=1; i<=n; i++ )
    {
        in>>T[i].tip;
        in>>T[i].val;
        Sn[i]=T[i].val;
    }
    sort ( Sn+1,Sn+n+1 );
    for ( i=1; i<=n; i++ )
    {
        if ( T[i].tip == 1 )
        {
            V[ b_search(T[i].val) ]=1;
        }
        if ( T[i].tip == 2 )
        {
            V[ b_search(T[i].val) ]=0;
        }
        if ( T[i].tip == 3 )
        {
            out<< V[ b_search(T[i].val) ] << "\n";
        }
    }
}