Cod sursa(job #1144247)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 16 martie 2014 19:55:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include<fstream>
#include<vector>

using namespace std;

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

const int mod = 666013;
vector <int> h[ mod ];

int main()
{
    int p, x, n, key, j;
    bool ok;
    fin>>n;
    for( int i = 0; i < n; ++ i ) {
        ok = 0;
        fin>>p>>x;
        key = x % mod;
        for( j = 0; j < (int)h[ key ].size(); ++ j ) {
            if ( h[ key ][ j ] == x ) {
                ok = 1;
                break;
            }
        }
        if ( p == 1 ) {
            if ( ok == 0 ) {
                h[ key ].push_back( x );
            }
        } else if ( p == 2 ) {
            if ( ok == 1 ) {
                h[ key ][ j ] = h[ key ][ h[key].size() - 1 ];
                h[ key ].resize( h[key].size() - 1 );
            }
        } else if ( p == 3 ) {
            fout<<ok<<'\n';
        }
    }
    fin.close();
    fout.close();
    return 0;
}