Cod sursa(job #2183907)

Utilizator Athena99Anghel Anca Athena99 Data 23 martie 2018 16:07:53
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int mod= 666013;

vector <int> v[mod];

int check( int x ) {
    for ( int i= 0; i<(int)v[x%mod].size(); ++i ) {
        if ( v[x%mod][i]==x ) {
            return i;
        }
    }

    return -1;
}

int main(  ) {
    int q;
    for ( fin>>q; q>0; --q ) {
        int x, y;
        fin>>x>>y;

        if ( x==1 && check(y)==-1 ) {
            v[y%mod].push_back(y);
        } else if ( x==2 ) {
            int pos= check(y);
            if ( pos!=-1 ) {
                v[y%mod][pos]= v[y%mod].back();
                v[y%mod].pop_back();
            }
        } else if ( x==3 ) {
            if ( check(y)==-1 ) {
                fout<<"0\n";
            } else {
                fout<<"1\n";
            }
        }
    }

    return 0;
}