Cod sursa(job #1265854)

Utilizator lolmanDomuta Dariu lolman Data 17 noiembrie 2014 21:08:28
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.28 kb
#include <iostream>
#include <stdio.h>
#include <vector>
#include <fstream>
#define nmax 1000001
#define mod 666013
using namespace std;
vector <int> g[nmax];
int sol,ok,op,it;
long long i,j,n,x;
int find_value(int x)
       {
           int list=x % mod;
           ok=0;
           for(i=0;i<g[list].size();i++)
                 if ( g[list][i]==x ) {ok=1;break;}
            if (ok==1) return i; else return -1;
       }

void insert_value (int x)
       {
           int list=x % mod;
           it=find_value(x);
           if (it==-1) g[list].push_back(x);
       }

void delete_value (int x)
       {
           int list=x % mod;
           it = find_value(x);
           if (it!=-1) {
                  g[list][it]=g[list][g[list].size()-1];
                  g[list].pop_back();
                       }
       }
int main()
{
    ifstream f("hashuri.in");
    ofstream h("hashuri.out");
    f>>n;
    for (j=1;j<=n;j++)
      {
          f>>op>>x;
          if (op==1) insert_value(x);
          if (op==2) delete_value(x);
          if (op==3)
                      {
                      sol=find_value(x);
                      if(sol!=-1) h<<"1"<<'\n';
                      else h<<"0"<<'\n';
                       }

      }

    return 0;
}