Cod sursa(job #2741924)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 19 aprilie 2021 19:06:50
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.69 kb
#pragma GCC optimize("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 << 16);
    char buffer[(1 << 16)];
    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;
    }
};

struct betterHash
{
    const int magic = 0x45d9f3b;
    size_t operator()(int32_t x) const
    {
        x = ((x >> 16) ^ x) * magic;
        x = ((x >> 16) ^ x) * magic;
        x = (x >> 16) ^ x;

        return x;
    }
};

inParser in("hashuri.in");
gp_hash_table<int, null_type, betterHash> s;
char outBuffer[(1 << 20)];
FILE *out = fopen("hashuri.out", "w");

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':
                s.erase(x);
                break;
            default:
                outBuffer[index++] = '0' + (s.find(x) != s.end());
                outBuffer[index++] = '\n';
        }
    }
 
    fwrite(outBuffer, 1, index, out);
}