Cod sursa(job #2405129)

Utilizator AkrielAkriel Akriel Data 13 aprilie 2019 23:00:03
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.8 kb
#include <fstream>

#define debug(x) cerr << #x": " << x << "\n"

using namespace std;

const int P1 = 1620817;
const int P2 = 1620823;
const int P3 = 1620827;
const int P4 = 1620831;

long long tableOne  [P1];
long long tableTwo  [P2];
long long tableThree[P3];
long long tableFour [P4];

ifstream cin("hashuri.in");
ofstream cout("hashuri.out");

bool isIn(int number){
    int pos[4];
    pos[0] = number%P1;
    pos[1] = number%P2;
    pos[2] = number%P3;
    pos[3] = number%P4;

    if (tableOne[pos[0]] == number or tableTwo[pos[1]] == number or tableThree[pos[2]] == number or tableFour[pos[3]] == number)
        return true;
    else
        return false;
}

int main(){
    int tests;
    cin >> tests;

    int operation;
    long long number;
    for (; tests; tests--){
        cin >> operation >> number;

        int pos[4];
        pos[0] = number%P1;
        pos[1] = number%P2;
        pos[2] = number%P3;
        pos[3] = number%P4;


        if (operation == 1){
            if (isIn(number) == false){
                tableOne  [pos[0]] = number;
                tableTwo  [pos[1]] = number;
                tableThree[pos[2]] = number;
                tableFour [pos[3]] = number;
            }
        }

        if (operation == 2){
            if (tableOne[pos[0]] == number)
                tableOne[pos[0]] = 0;

            if (tableTwo[pos[1]] == number)
                tableTwo[pos[1]] = 0;

            if (tableThree[pos[2]] == number)
                tableThree[pos[2]] = 0;

            if (tableFour[pos[3]] == number)
                tableFour[pos[3]] = 0;
        }

        if (operation == 3){
            if (isIn(number))
                cout << "1\n";
            else
                cout << "0\n";
        }
    }
}