Cod sursa(job #1935938)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 22 martie 2017 19:07:37
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");

typedef long long int ll;

const int NMax = 276997;
const int BMax = 5e4 + 5;

ll v[NMax];

int pos = BMax - 1;
char Buffer[BMax];
inline void Read(ll &x) {
    while(!isdigit(Buffer[pos])) {
        if(++pos == BMax) {
            pos = 0;
            fin.read(Buffer, sizeof(Buffer));
        }
    }
    x = 0;
    while(isdigit(Buffer[pos])) {
        x = x * 10 + (Buffer[pos] - '0');
        if(++pos == BMax) {
            pos = 0;
            fin.read(Buffer, sizeof(Buffer));
        }
    }
}

inline bool Binary(const ll &value) {
    int lo = 0;
    int hi = NMax - 1;

    while(lo <= hi) {
        int mid = (lo + hi) >> 1;

        if(v[mid] == value) return true;
        if(v[mid] < value) {
            lo = mid + 1;
        } else {
            hi = mid - 1;
        }
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);

    for(int i = 1; i <= NMax; i++) Read(v[i]);

    ll n;
    Read(n);

    int ans = 0;
    while(n--) {
        ll x;
        Read(x);

        if(Binary(x) == true) ans++;
    }

    fout << ans;
    return 0;
}