Cod sursa(job #2680177)

Utilizator AndreeaGherghescuAndreea Gherghescu AndreeaGherghescu Data 2 decembrie 2020 20:43:42
Problema Dtcsu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

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

const int mod=10007;

vector <long long> v[mod];

int main() {
    long long cate=0,x,q;
    for (long long i=1;i<=276997;i++)
    {
        in>>x;
        v[x%mod].push_back(x);
    }
    for (long long i=0;i<mod;i++)
        sort (v[i].begin(),v[i].end());
    in>>q;
    while (q--)
    {
        in>>x;
        long long rest=x%mod;

        if (v[rest].empty()) continue;
        if (x<v[rest][0]) continue;

        long long mij,p,u;
        p=0;
        u=v[rest].size()-1;
        while (p<u)
        {
            mij=(p+u)/2;
            if (v[rest][mij]>x)
                u=mij-1;
            else if (v[rest][mij]<x)
                p=mij+1;
            else p=u=mij;
        }
        if (v[rest][u]==x) cate++;
    }
    out<<cate;
    return 0;
}