Cod sursa(job #1220507)

Utilizator ptquake10ptquake10 ptquake10 Data 17 august 2014 15:28:10
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <map>
using namespace std;
#define MAX 12345

int n, k, p;
vector<int> m[MAX];

int pos(int x) {
	int k = x % MAX;
	for (int i = 0; i < m[k].size(); i++)
		if (m[k][i] == x) return i;
	return -1;
}

int main() {
	int op, x;
	
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &op, &x);
		k = x % MAX;
		switch(op) {
			case 1:
				p = pos(x);
				if (p == -1) m[k].push_back(x);
				break;
			case 2:
				p = pos(x);
				if (p != -1) {
					m[k][p] = m[k][m[k].size()-1];
					m[k].pop_back();
				}
				break;
			case 3:
				p = pos(x);
				if (p != -1) printf("1\n"); else printf("0\n");
		}
	}
	
	return 0;
}