Pagini recente » Cod sursa (job #2021133) | Cod sursa (job #154540) | Cod sursa (job #1784448) | Cod sursa (job #2895544) | Cod sursa (job #2783992)
#include <bits/stdc++.h>
using namespace std;
struct InParser {
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
InParser(const char *nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int64_t &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
int64_t sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
void close() {
fclose(fin);
}
};
InParser fin("dtcsu.in");
ofstream fout("dtcsu.out");
typedef struct element {
int64_t val;
element *next;
} *lista;
const int MASK = (1 << 23) - 1;
const int mod = 12289;
bitset<MASK + 1> filter;
lista h[mod];
void add(int64_t x) {
filter[x & MASK] = true;
int key = x % mod;
lista p;
for (p = h[key]; p; p = p->next) {
if (p->val == x) {
return;
}
}
p = new element;
p->val = x;
p->next = h[key];
h[key] = p;
}
bool check(int64_t x) {
if (filter[x & MASK] == false) {
return false;
}
int key = x % mod;
for (lista p = h[key]; p; p = p->next) {
if (p->val == x) {
return true;
}
}
return false;
}
void test_case() {
for (int i = 1; i <= 276997; ++i) {
int64_t x;
fin >> x;
add(x);
}
int64_t q;
fin >> q;
int ans = 0;
for (int i = 1; i <= q; ++i) {
int64_t x;
fin >> x;
ans += check(x);
}
fout << ans << '\n';
}
int main(){
int t = 1;
for (int tc = 1; tc <= t; ++tc) {
test_case();
}
fin.close();
fout.close();
return 0;
}