Cod sursa(job #2805717)

Utilizator Langa_bLanga Radu Langa_b Data 21 noiembrie 2021 19:46:28
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>
#define mod 666013
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
vector<vector<int>>hashu(mod + 2);
vector <int> inter;
int n;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int type, nr;
		cin >> type >> nr;
		int cat, rest;
		cat = nr / mod;
		rest = nr % mod;
		bool ok = 0;
		int loc = 0;
		vector<int>::iterator itr, j;
		for (j = hashu[rest].begin(); j != hashu[rest].end(); j++) {
			if ((*j) == cat) {
				ok = 1;
				itr = j;
				break;
			}
		}
		if (type == 2) {
			if (ok == 1) {
				hashu[rest].erase(itr);
			}
		}
		else if(type == 1){
			if (ok == 0) {
				hashu[rest].emplace_back(cat);
			}
		}
		else if (type == 3) {
			if (ok == 1) {
				cout << 1 << '\n';
			}
			else {
				cout << 0 << '\n';
			}
		}
	}
}