Pagini recente » Cod sursa (job #2671183) | Cod sursa (job #144716) | Cod sursa (job #2268282) | Cod sursa (job #875043) | Cod sursa (job #1706171)
#include <bits/stdc++.h>
#include <tr1/unordered_set>
const int DIM = 1 << 20;
const int MOD = (1 << 16) - 1;
using namespace std;
int n, q, x, k, p; char buffer[DIM];
vector <int> my_hash[MOD + 1];
class input_reader {
private:
FILE *input_file;
static const int SIZE = 1 << 12;
char buffer[SIZE]; int cursor;
inline void advance() {
if( ++cursor == SIZE ) {
cursor = 0;
fread( buffer, SIZE, 1, input_file );
}
return;
}
inline char current() {
return buffer[cursor];
}
public:
input_reader( const char *file_name, const char *file_type ) {
input_file = fopen( file_name, file_type ); cursor = 0;
fread( buffer, SIZE, 1, input_file );
}
input_reader &operator >>( int &value ) {
value = 0;
while( current() < '0' || current() > '9' )
advance();
while( current() >= '0' && current() <= '9' ) {
value = value * 10 + ( current() - '0' );
advance();
}
return *this;
}
} input_file( "hashuri.in", "r" );
FILE *output_file = fopen( "hashuri.out", "w" );
int main( void ) {
input_file >> n;
for( int i = 1; i <= n; i ++ ) {
input_file >> q >> x; p = x & MOD;
switch(q) {
case 1: {
if( find( my_hash[p].begin(), my_hash[p].end(), x ) == my_hash[p].end() )
my_hash[p].push_back(x);
break;
}
case 2: {
if( find( my_hash[p].begin(), my_hash[p].end(), x ) != my_hash[p].end() )
my_hash[p].erase( find( my_hash[p].begin(), my_hash[p].end(), x ) );
break;
}
case 3: {
buffer[k++] = '0' + ( find( my_hash[p].begin(), my_hash[p].end(), x ) != my_hash[p].end() );
buffer[k++] = '\n';
break;
}
}
}
fwrite( buffer, 1, DIM, output_file );
return 0;
}