Cod sursa(job #770959)

Utilizator veleanduAlex Velea veleandu Data 24 iulie 2012 14:06:13
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 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; short tip; } query;
    query T[maxn];
    long n,i,j;
    long S[maxn],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;
        S[i]=T[i].val;
    }
    sort ( S+1,S+n+1 );
    for ( i=1; i<=n; )
    {
        j=i;
        while ( ( S[i] == S[j]) && (i<=n) )
            i++;
        l++;
        Sn[l]=S[j];
    }
    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";
        }
    }
}