Cod sursa(job #3209350)

Utilizator Latyn76Tinica Alexandru Stefan Latyn76 Data 2 martie 2024 11:42:50
Problema Dtcsu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");
long long a[280000];

int cautbin(long long x) {
    int st = 1, dr = 276997;
    while (st <= dr) {
        int mij = (st + dr) / 2;
        if (a[mij] == x)
            return 1;
        else if (a[mij] < x)
            st = mij + 1;
        else dr = mij - 1;
    }
    return 0;
}

int main()
{
    int i, n, r, Q, cnt = 0, gasit;
    long long x;
    for (i = 1; i <= 276997; i++)
    {
        fin >> x;
        a[i] = x;
    }
    sort(a + 1, a + 276998);
    fin >> Q;
    while (Q--)
    {
        fin >> x;
        if (x > 0)
        {
            cnt += cautbin(x);
        }
    }
    fout << cnt << "\n";
    return 0;
}