Cod sursa(job #1735709)

Utilizator danutbodbodnariuc danut danutbod Data 30 iulie 2016 18:33:17
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 3.74 kb
#include <cstdio>
#include <set>
using namespace std;
int n,op,x,i;
set<int> A; //arbore echilibrat binar operatii O(log(n))-insert, erase,find

int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    scanf("%d", &n);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d", &op, &x);
        if (op == 1)
        {   A.insert(x); continue; }
        if (op == 2)
        {   A.erase(x);  continue; }
        printf("%d\n", A.find(x) != A.end());
    }
   return 0;
}












































//#include <stdio.h>
//#include <map> //arbore echilibrat binar O(log(n)) - operatiile
//
//using namespace std;
//
//int N, NR;
//map <int, int> M;
//
//int main()
//{
//    freopen("hashuri.in", "r", stdin);
//    freopen("hashuri.out", "w", stdout);
//
//    int i, tip, x;
//
//    scanf("%d ", &N);
//
//    for (i = 1; i <= N; i++)
//    {
//        scanf("%d %d ", &tip, &x);
//
//        if (tip == 1 && M.find(x)==M.end()) M[x] = ++NR;
//        if (tip == 2) M.erase(x);
//        if (tip == 3) printf("%d\n", M.find(x) != M.end());
//    }
//
//    return 0;
//}
//#include <iostream>
//#include <algorithm>
//#include <vector>
//#define MAXN 100000
//using namespace std;
//
//int N,val,Type;
//vector <int>H[MAXN];
//void Add(int v)
//{
//    int S=v%MAXN;
//    for(int i=0;i<H[S].size();i++)
//        if(H[S][i]==v)
//            return;
//    H[S].push_back(v);
//}
//void Delete(int v)
//{
//    int S=v%MAXN;
//    for(int i=0;i<H[S].size();i++)
//        if(H[S][i]==v)
//        {
//            H[S].erase(H[S].begin()+i);
//            return;
//        }
//}
//void Search(int v)
//{
//    int S=v%MAXN;
//    for(int i=0;i<H[S].size();i++)
//        if(H[S][i]==v)
//        {
//            printf("1\n");
//            return;
//        }
//    printf("0\n");
//}
//int main()
//{
//    freopen("hashuri.in","r",stdin);
//    freopen("hashuri.out","w",stdout);
//    scanf("%d",&N);
//    for(int i=1;i<=N;i++)
//    {
//        scanf("%d%d",&Type,&val);
//        if(Type==1)Add(val);
//        else if(Type==2)Delete(val);
//        else Search(val);
//    }
//    return 0;
//}
//#include <iostream>
//#include <stdio.h>
//#include <fstream>
//#include <vector>
//using namespace std;
//ifstream f("hashuri.in");
//ofstream g("hashuri.out");
//
//
//vector<int> G[66001];
//int key=66001;
//
//vector<int>::iterator find_element(int val,int list)
//{
//    vector<int>::iterator it;
//    for( it=G[list].begin(); it < G[list].end(); it++)
//    if(*it==val)
//    return it;
//
//    return G[list].end();
//
//}
//
//void insert_element(int val)
//{
//    int list=val%key;
//    if(find_element(val,list)==G[list].end())
//    {
//        G[list].push_back(val);
//    }
//}
//
//void erase_element(int val)
//{
//    int list=val%key;
//     vector<int>::iterator it = find_element(val,list);
//
//    if(it!=G[list].end())
//    G[list].erase(it);
//
//}
//
//void bool_exist(int val)
//{
//    int list=val%key;
//    vector<int>::iterator it = find_element(val,list);
//    if(it==G[list].end())
//    g<<"0"<<'\n';
//    else
//    g<<"1"<<'\n';
//}
//
//int main()
//{
//    int nrOperatii;
//    int op;
//    int val;
//
//    f>>nrOperatii;
//
//    for(int i=1;i<=nrOperatii;i++)
//    {
//        f>>op>>val;
//        if(op==1)
//        insert_element(val);
//        else
//        {
//            if(op==2)
//            erase_element(val);
//            else
//            {
//
//                bool_exist(val);
//            }
//        }
//    }
//
//    f.close();
//    g.close();
//
//    return 0;
//}