Cod sursa(job #3319138)

Utilizator horatiu.avramAvram Popa Cristian Horatiu horatiu.avram Data 30 octombrie 2025 17:42:09
Problema Dtcsu Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include<bits/stdc++.h>

using namespace std;

const int MOD=8192;
const int BUFSIZE=128*1024;

vector<long long>table[MOD];

int rpos=BUFSIZE-1;
char rbuf[BUFSIZE];

FILE *fin,*fout;

static inline char readChar() {
    if(!(rpos=(rpos+1)&(BUFSIZE-1))) {
        fread(rbuf,1,BUFSIZE,fin);
    }
    return rbuf[rpos];
}

long long readInt() {
    char ch;
    long long res=0;
    while(isspace(ch=readChar()));
    do {
        res=10*res+ch-'0';
    } while(isdigit(ch=readChar()));
    return res;
}

bool searching(long long x) {
    int val=x%MOD;
    for(auto it:table[val]) {
        if(it==x) {
            return true;
        }
    }
    return false;
}

void adding(long long x) {
    int val=x%MOD;
    table[val].push_back(x);
}

void read_input() {
    int n=276997;
    long long x;
    while(n--) {
        x=readInt();
        adding(x);
    }
}

void process_queries() {
    int res=0,num_queries;
    long long x;
    num_queries=readInt();
    while(num_queries--) {
        x=readInt();
        res+=searching(x);
    }
    fprintf(fout,"%d",res);
}

void open_files() {
    fin=fopen("dtcsu.in","r");
    fout=fopen("dtcsu.out","w");
}

void close_files() {
    fclose(fin);
    fclose(fout);
}
int main() {
    open_files();
    read_input();
    process_queries();
    close_files();
    return 0;
}