Cod sursa(job #640585)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 25 noiembrie 2011 23:25:59
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.55 kb
#include <fstream>
#include <vector>

#define P 2003

using namespace std;

long n, i, t, v, o;
char st[1000010], gh[2000010];
vector <long> V[P + 10];

inline vector<long>::iterator find_value(long x) {
    long aux = v % P;
    vector<long>::iterator it;

    for (it = V[aux].begin(); it != V[aux].end(); ++it)
        if (*it == x)
            return it;
		
    return V[aux].end();
}

int main() {
	//ifstream fin("hashuri.in");
	//ofstream fout("hashuri.out");
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	
	//fin>>n;
	scanf("%ld\n", &n);
	//gets(gh);
	
	for (i = 1; i <= n; ++i) {
		gets(gh);
		long h = 0;
		t = 0, v = 0;
		while (gh[h] != ' ') 
			t *= 10, t += (long)(gh[h] - '0'), ++h;
		++h;
		while (h < strlen(gh)) 
			v *= 10, v += (long)(gh[h] - '0'), ++h;
		//t = 1;
		//v = i;
		if (t == 1) {
			long aux = v % P;
			long S = V[aux].size();
			long ok = 0;
			for (long j = 0; j < S; ++j)
				if (V[aux][j] == v) {
					ok = 1;
					break;
				}
			if (!ok) V[aux].push_back(v);
		}
		if (t == 2) {
			long aux = v % P;			
			vector<long>::iterator it = find_value(v);
			
			if (it != V[aux].end())
				V[aux].erase(it);
			
			//V[aux].erase(v);
		}
		if (t == 3) {
			long aux = v % P;
			long S = V[aux].size();
			long ok = 0;
			for (long j = 0; j < S; ++j)
				if (V[aux][j] == v) {
					//fout<<"1"<<"\n";
					st[o++] = '1';
					st[o++] = '\n';
					ok = 1;
					break;
				}			
			if (!ok) {
				//fout<<"0"<<"\n";
				st[o++] = '0';
				st[o++] = '\n';				
			}
		}
	}
	printf("%s", st);
	return 0;
}