Cod sursa(job #2741878)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 19 aprilie 2021 17:34:44
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.61 kb
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

class inParser
{
private:
    FILE *in;

    const int sz = (1 << 18);
    char buffer[(1 << 18)];
    int index;

    __attribute__((always_inline)) char getCh()
    {
        if(index == sz)
            fread(buffer, 1, sz, in), index = 0;

        return buffer[index++];
    }

public:
    inParser(const char* name)
    {
        in = fopen(name, "r");
        index = sz;
    }

    char getTag()
    {
        int ch = getCh();
        getCh();
        return ch;
    }

    int getNum()
    {
        int ret = 0;
        for(char ch = getCh(); '0' <= ch && ch <= '9'; ch = getCh())
            ret = ret * 10 + ch - '0';

        return ret;
    }
};

inParser in("hashuri.in");
gp_hash_table<int, null_type> s({}, {}, {}, {}, {1 << 21});
char outBuffer[(1 << 20)];

int main()
{
    inParser in("hashuri.in");
    int n; n = in.getNum();
    int index = 0;

    for(int i = 0; i < n; i++)
    {
        char q = in.getTag();
        int x = in.getNum();
        switch(q)
        {
            case '1':
                s.insert(x);
                break;
            case '2':
                if(s.find(x) != s.end())
                    s.erase(x);
                break;
            default:
                if(s.find(x) != s.end())
                    outBuffer[index++] = '1';
                else
                    outBuffer[index++] = '0';
                outBuffer[index++] = '\n';
        }
    }

    FILE *out = fopen("hashuri.out", "w");
    fwrite(outBuffer, 1, index, out);
}