Pagini recente » Cod sursa (job #2301216) | Cod sursa (job #1841576) | Cod sursa (job #575268) | Cod sursa (job #1182636) | Cod sursa (job #3277713)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
const int NMAX = 1e6;
const int MOD = 666013;
const int BAZA = 29;
vector<int> buck[MOD + 1];
int hashh(int x){
int cnt = 0;
long long sum = 0;
while(x){
sum = (sum + (long long)pow(BAZA, cnt) * (x % 10) % MOD) % MOD;
cnt ++;
x /= 10;
}
return sum;
}
int main()
{
int q;
f >> q;
for(int i=1; i<=q; i++){
int tip, val;
f >> tip >> val;
if(tip == 1){
bool ok = false;
int idx = hashh(val);
for(int i=0; i<buck[idx].size(); i++)
if(buck[idx][i] == val)
ok = true;
if(ok == false)
buck[idx].push_back(val);
}else if(tip == 2){
int ok = -1;
int idx = hashh(val);
for(int i=0; i<buck[idx].size(); i++)
if(buck[idx][i] == val)
ok = i;
if(ok > -1){
buck[idx].erase(buck[idx].begin() + ok);
}
}else{
bool ok = false;
int idx = hashh(val);
for(int i=0; i<buck[idx].size(); i++)
if(buck[idx][i] == val)
ok = true;
if(ok == true){
g << 1 << "\n";
}else g << 0 << "\n";
}
}
return 0;
}