Cod sursa(job #2205397)

Utilizator RobybrasovRobert Hangu Robybrasov Data 19 mai 2018 00:07:13
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <bits/stdc++.h>

#define SMAX 16384
#define N 276997
#define MOD 666013
#define ll long long

using namespace std;

char s[SMAX];
int p;
FILE *f;
forward_list<char> H[666013];

void read(ll &x) {
    x = 0;
    for (; s[p] >= '0' && s[p] <= '9'; ++p) {
        x = 10 * x + s[p] - '0';
        if (p == SMAX - 1) {
            fread(s, 1, SMAX, f);
            p = -1;
        }
    }
    for (; s[p] < '0' || s[p] > '9'; ++p) {
        if (p == SMAX - 1) {
            fread(s, 1, SMAX, f);
            p = -1;
        }
    }
}

inline void insert(ll x) {
    int pos = x % MOD;
    auto it = H[pos].begin();
    for (; it != H[pos].end() && *it != x; ++it);
    if (it == H[pos].end()) {
        H[pos].push_front(x);
    }
}

inline bool contains(ll x) {
    int pos = x % MOD;
    auto it = H[pos].begin();
    for (; it != H[pos].end() && *it != x; ++it);
    return it != H[pos].end();
}

int main() {
    f = fopen("dtcsu.in", "r");
    ofstream fout("dtcsu.out");

    fread(s, 1, SMAX, f);
    p = 0;

    for (int i = 0; i < N; ++i) {
        ll x;
        read(x);
        insert(x);
    }
    ll n;
    read(n);
    int k = 0;
    while (n--) {
        ll x;
        read(x);
        if (contains(x)) {
            ++k;
        }
    }
    fout << k << "\n";

    return 0;
}