Cod sursa(job #1825258)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 8 decembrie 2016 21:45:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int MOD=100007;
vector<int> a[MOD];
int v[MOD];
int ad(int x)
{
    int i,h;
    h=x%MOD;
    for(i=0;i<v[h];i++)
    if(a[h][i]==x) return 0;
    a[h].push_back(x);
    v[h]++;
}
int sterg(int x)
{
    int i,h;
    h=x%MOD;
    for(i=0;i<v[h];i++)
    if(a[h][i]==x)
    {
        swap(a[h][i],a[h][v[h]-1]);
        a[h].pop_back();
        v[h]--;
    }
}
bool loc(int x)
{
    int h=x%MOD;
    int i;
    for(i=0;i<v[h];i++)
    if(a[h][i]==x) return true;
    return false;
}
int main()
{int i,x,y,n;
f>>n;
for(i=1;i<=n;i++)
{
    f>>y>>x;
    if(y==3)
    g<<loc(x)<<'\n';
    else
    {
        if(y==2)
        sterg(x);
        else ad(x);
    }
}
    return 0;
}