Cod sursa(job #2417146)

Utilizator mihneacazCazacu Mihnea mihneacaz Data 28 aprilie 2019 23:39:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.28 kb
#include <fstream>
#include <vector>
#include <algorithm>

const int MOD=1000003;

using namespace std;

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

vector <int> v[MOD+5];

void solve1(int val)
{
    int root=val%MOD;
    bool found=0;
    for(auto x: v[root])
        if(x==val){
            found=1;
            break;
        }
    if(found==0)
        v[root].push_back(val);
}

void solve2(int val)
{
    int root=val%MOD;
    bool found=0;
    int pos=0;
    for(int i=0; i<v[root].size(); ++i){
        if(v[root][i]==val){
            found=1;
            pos=i;
            break;
        }
    }
    if(found==1){
        swap(v[root][pos],v[root].back());
        v[root].pop_back();
    }
}

void solve3(int val)
{
    int root=val%MOD;
    int sol=0;
    for(auto x: v[root])
        if(x==val){
            sol=1;
            break;
        }
    cout<<sol<<'\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i){
        int op,x;
        cin>>op>>x;
        switch(op){
            case 1: solve1(x); break;
            case 2: solve2(x); break;
            case 3: solve3(x); break;
        }
    }
    return 0;
}