Cod sursa(job #2357442)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 27 februarie 2019 13:33:07
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.01 kb
/*
    ** Code by
    ** ARHIRE ANDREI
*/

#include <bits/stdc++.h>
#define MOD 666013
#define lista x % MOD
using namespace std;

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

vector < pair < int , int > > v [ MOD ] ;

pair < int , int > find_element ( int x )
{
    vector < pair < int , int > > :: iterator it ;
    pair < int , int > sol ;
    for ( it = v[ lista ].begin() ; it != v[ lista ].end() ; it ++ )
        if ( (*it).first == x )
           {
               sol.first = (*it).first ;
               sol.second = (*it).second ;
               return sol ;
           }

    sol.first = -1 ;
    sol.second = -1 ;
    return sol ;
}

void push_element ( int x )
{
     vector < pair < int , int > > :: iterator it ;

    for ( it = v[ lista ].begin() ; it != v[ lista ].end() ; it ++ )
        if ( (*it).first == x ) { (*it).second ++ ; return ; }

    v [ lista ].push_back( { x , 1 } ) ;
}

int aparitii_element ( int x )
{
    vector < pair < int , int > > :: iterator it ;

    for ( it = v [ lista ].begin() ; it != v [ lista ].end() ; it ++ )
        if ( ( *it ).first == x )   return ( *it ).second ;
}

void delete_aparitie ( int x )
{
     vector < pair < int , int > > :: iterator it ;

    for ( it = v [ lista ].begin() ; it != v [ lista ].end() ; it ++ )
        if ( ( *it ).first == x )
        {
            ( *it ).second -- ;
            if ( ( *it ).second == 0 )  v [ lista ].erase(it) ;
            return ;
        }

}

int n , type , value ;

int main()
{
    pair < int , int > X ;

    in >> n ;
    while ( n -- )
    {
        in >> type >> value ;
        if ( type == 1 )    push_element( value ) ;
        if ( type == 2 )    delete_aparitie( value ) ;
        if ( type == 3 )
        {
            X = find_element( value ) ;
            if ( X.first == -1 && X.second == -1 )  out << "0\n" ;
            else                                    out << "1\n" ;       //cout << X.second << '\n' ;
        }
    }
}