Pagini recente » Cod sursa (job #954430) | Cod sursa (job #770957)
Cod sursa(job #770957)
#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 )
{
cout<< V[ b_search(T[i].val) ] << "\n";
}
}
}