Pagini recente » Clasament cariera_1 | Clasamentul arhivei de probleme | Cod sursa (job #741223) | Cod sursa (job #2091813) | Cod sursa (job #1706173)
#include <bits/stdc++.h>
using namespace std;
constexpr unsigned MAX_N = 1000000;
constexpr unsigned BUFFSIZE = 258257;
constexpr unsigned MOD = (1 << 16) - 1;
bool digit[256];
inline char getChar() {
static char buff[BUFFSIZE];
static int pos = BUFFSIZE;
if (pos == BUFFSIZE) {
fread(buff, 1, BUFFSIZE, stdin);
pos = 0;
}
return buff[pos++];
}
inline unsigned readInt() {
unsigned q = 0;
char c = getChar();
while (!digit[c])
c = getChar();
while (digit[c]) {
q = (q << 1) + (q << 3) + (c - '0');
c = getChar();
}
return q;
}
struct List {
unsigned v;
unsigned next;
};
List adj[MAX_N + 1];
unsigned head[MOD + 1];
unsigned ptr = 1;
inline void hashInsert(const unsigned arg) {
const unsigned headPtr = (arg ^ 0x9e3779b9 + (arg << 6) + (arg >> 2)) & MOD;
adj[ptr].v = arg;
adj[ptr].next = head[headPtr];
head[headPtr] = ptr++;
}
inline void hashErase(const unsigned arg) {
const unsigned headPtr = (arg ^ 0x9e3779b9 + (arg << 6) + (arg >> 2)) & MOD;
if (adj[head[headPtr]].v == arg)
head[headPtr] = adj[head[headPtr]].next;
else {
unsigned iter = head[headPtr];
while (adj[iter].next && adj[adj[iter].next].v != arg)
iter = adj[iter].next;
if (adj[iter].next)
adj[iter].next = adj[adj[iter].next].next;
}
}
inline bool hashFind(const unsigned arg) {
const unsigned headPtr = (arg ^ 0x9e3779b9 + (arg << 6) + (arg >> 2)) & MOD;
unsigned iter = head[headPtr];
while (iter && adj[iter].v != arg)
iter = adj[iter].next;
return iter;
}
char out[MAX_N + MAX_N + 1];
int main() {
for (unsigned i = 0; i < 10; i += 1)
digit['0' + i] = 1;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
unsigned q = readInt();
unsigned outPtr = 0;
for (unsigned testPtr = 0; testPtr < q; testPtr += 1) {
unsigned opType = readInt() - 1, arg = readInt();
if (!opType) {
hashInsert(arg);
} else if (opType == 1) {
hashErase(arg);
} else {
out[outPtr] = '0' + hashFind(arg);
out[outPtr + 1] = '\n';
outPtr += 2;
}
}
fclose(stdin);
fwrite(out, 1, outPtr, stdout);
fclose(stdout);
return 0;
}