Cod sursa(job #1513991)

Utilizator Kira96Denis Mita Kira96 Data 30 octombrie 2015 13:59:10
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.88 kb
#include <fstream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
const int mod = 3000000;
int v[mod], n, tip, x;
int main () {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> tip >> x;
        if (tip == 1) {
            int pos = -1;
            int p = x % mod;
            for (int j = 0; ; ++j) {
                if (j) {
                    p += 2 * (j - 1) + 1;
                }
                if (p >= mod) {
                    p -= mod;
                }
                if (v[p] == -1) {
                    pos = p;
                }
                if (v[p] == 0) {
                    if (pos != -1) {
                        v[pos] = x;
                    } else {
                        v[p] = x;
                    }
                    break;
                } else if (v[p] == x) {
                    break;
                }
            }
        } else if (tip == 2) {
            int found = -1;
            int p = x % mod;
            for (int j = 0; ; ++j) {
                if (j) {
                    p += 2 * (j - 1) + 1;
                }
                if (p >= mod) {
                    p -= mod;
                }
                if (v[p] == x) {
                    v[p] = -1;
                    break;
                } else if (v[p] == 0) {
                    break;
                }
            }
        } else if (tip == 3) {
            int found = 0;
            int p = x % mod;
            for (int j = 0; ; ++j) {
                if (j) {
                    p += 2 * (j - 1) + 1;
                }
                if (p >= mod) {
                    p -= mod;
                }
                if (v[p] == x) {
                    found = 1;
                    break;
                } else if (v[p] == 0) {
                    break;
                }
            }
            cout << found << "\n";
        }
    }
}