Pagini recente » Cod sursa (job #1945177) | Cod sursa (job #1400283) | Cod sursa (job #1606662) | Cod sursa (job #2525094) | Cod sursa (job #1862601)
#include <bits/stdc++.h>
using namespace std;
FILE *fin;
ofstream fout("hashuri.out");
#define BUF 1 << 17
int pos = BUF;
char buf[BUF];
inline char next() {
if(pos == BUF)
fread(buf, 1, BUF, fin), pos = 0;
return buf[pos++];
}
inline int read() {
int x = 0, semn = 1;
char ch = next();
while(!isdigit(ch) && ch != '-')
ch = next();
if(ch == '-')
ch = next(), semn = -1;
while(isdigit(ch))
x = x * 10 + ch - '0', ch = next();
return x * semn;
}
#define Hsize 16383
class myHash {
vector<int> v[Hsize + 1];
public:
inline bool check( int val ) {
unsigned int i, h;
h = val & Hsize;
i = 0;
while ( i < v[h].size() && v[h][i] != val )
i ++;
return ( i < v[h].size() );
}
inline bool pop( int val ) {
unsigned int i, h;
h = val & Hsize;
i = 0;
while ( i < v[h].size() && v[h][i] != val )
i ++;
if ( i < v[h].size() ) {
v[h][i] = v[h][v[h].size() - 1];
v[h].pop_back();
}
return ( i < v[h].size() );
}
inline void push( int val ) {
unsigned int h = val & Hsize;
v[h].push_back( val );
}
};
myHash hh;
int main() {
fin = fopen("hashuri.in", "r");
ofstream fout("hashuri.out");
int N = read();
for(int i = 0;i < N;i++) {
int op = read(), val = read();
if(op == 1) {
hh.push(val);
}
if(op == 2) {
hh.pop(val);
}
if(op == 3) {
int c = hh.check(val);
fout << c << '\n';
}
}
fclose(fin);
fout.close();
return 0;
}