Pagini recente » Cod sursa (job #520407) | Cod sursa (job #399015) | Cod sursa (job #799619) | Cod sursa (job #245973) | Cod sursa (job #2834325)
#include <fstream>
#include <vector>
using namespace std;
class InParser{
private:
vector < char > str;
int position;
ifstream fin;
char GetChar(){
if(position == (int) str.size()){
fin.read(str.data(), position);
position = 0;
}
return str[position++];
}
template < class DataType >
DataType GetInteger(){
char ch = GetChar();
while( ! isdigit(ch) && ch != '-')
ch = GetChar();
int sgn = 1;
if(ch == '-'){
sgn = -1;
ch = GetChar();
}
DataType number = 0;
while(isdigit(ch)){
number = number * 10 + ch - 48;
ch = GetChar();
}
return sgn * number;
}
public:
InParser(const string name): position(1e4), str(1e4), fin(name){}
~InParser(){
fin.close();
}
template < class DataType >
friend InParser& operator >> (InParser& in, DataType& number){
number = in.GetInteger< DataType >();
return in;
}
};
const int MOD = 123457;
vector < int > H[MOD];
inline static void Add(int value){
int key = value % MOD;
for(auto x: H[key])
if(x == value)
return ;
H[key].push_back(value);
}
inline static void Erase(int value){
int key = value % MOD;
int len = (int) H[key].size();
for(int i = 0; i < len; ++i)
if(value == H[key][i]){
H[key][i] = H[key][len - 1];
H[key].pop_back();
return ;
}
}
inline bool Find(int value){
int key = value % MOD;
for(auto x: H[key])
if(x == value)
return true;
return false;
}
int main(){
InParser fin("hashuri.in");
ofstream fout("hashuri.out");
int Queries, op, x;
fin >> Queries;
while(Queries--){
fin >> op >> x;
if(op == 1)
Add(x);
else if(op == 2)
Erase(x);
else
fout << Find(x) << '\n';
}
return 0;
}