Pagini recente » Cod sursa (job #20069) | Cod sursa (job #2667710) | Cod sursa (job #169848) | Cod sursa (job #67876) | Cod sursa (job #1846355)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
#define P 100003
void add(vector<queue<int> > &h, int val) {
int x;
for (unsigned int i = 0; i < h[val % P].size(); i++) {
x = h[val % P].front();
if (x == val) {
return;
}
h[val % P].pop();
h[val % P].push(x);
}
h[val % P].push(val);
}
void del(vector<queue<int> > &h, int val) {
int x;
for (unsigned int i = 0; i < h[val % P].size(); i++) {
x = h[val % P].front();
if (x == val) {
h[val % P].pop();
return;
}
h[val % P].pop();
h[val % P].push(x);
}
}
int query(vector<queue<int> > &h, int val) {
int x;
for (unsigned int i = 0; i < h[val % P].size(); i++) {
x = h[val % P].front();
if (x == val) {
return 1;
}
h[val % P].pop();
h[val % P].push(x);
}
return 0;
}
int main()
{
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, op, x;
vector<queue<int> > h (P);
fin >> n;
for (int i = 0; i < n; i++) {
fin >> op >> x;
if (op == 1) {
add(h, x);
} else if (op == 2) {
del(h, x);
} else {
fout << query(h, x) << "\n";
}
}
fin.close();
fout.close();
return 0;
}