Cod sursa(job #1647653)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 10 martie 2016 21:30:39
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <vector>
#define w 2000001
using namespace std;
vector <unsigned int> a[w];
unsigned int poz;
bool findh(unsigned int x)
{
    unsigned int i,fx=x;bool ok=1;
    x%=w;poz=-1;
    for (i=0;i<a[x].size()&&ok;i++)
    {
        if (a[x][i]==fx) poz=i,ok=0;
    }
    return !ok;
}
int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    unsigned int n,i,op,x;
    f>>n;
    for (i=1;i<=n;i++)
    {
        f>>op>>x;
        if (op==3) g<<findh(x)<<'\n';
        else
        {
            if (findh(x))
            {
                if (op==2) a[x%w].erase(a[x%w].begin()+poz);
            }
            else
            {
                if (op==1) a[x%w].push_back(x);
            }
        }
    }
    f.close();
    g.close();
    return 0;
}