Cod sursa(job #822294)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 23 noiembrie 2012 10:24:01
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
 # include <fstream>
 # include <cstring>
 # include <algorithm>
 # include <vector>

 # define dim 666013
 # define mod 666013


 using namespace std;

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

 vector < int > a[ dim ];
 int N;

 void adauga( int x )
 {
     if( a[ x % mod ].size() == 0 )
        a[ x % mod ].push_back( x );
 }

 void sterge( int x )
 {
     if ( a[ x % mod ].size() != 0 )
        a[ x % mod ].pop_back();
 }

 void afiseaza( int x )
 {
     vector < int > :: iterator it;
     int ok = 1;

     for ( it = a[ x % mod ].begin() ; it != a[ x % mod ].end() && ok == 1 ; ++it )
        if ( *it == x )
        {
            g << 1 << "\n";
            ok = 0;
        }

        if ( ok == 1 )
        g << 0 << "\n";

 }


 void citire()
 {
     int op, x, i;
     f >> N;
     for ( i = 1 ; i <= N ; i++ )
     {
         f >> op >> x;
         if ( op == 1 )
            adauga( x );
         else
         if ( op == 2 )
            sterge( x );
         else
         if ( op == 3 )
            afiseaza( x );
     }
 }

 int main()
 {
     citire();

 }