Cod sursa(job #2681050)

Utilizator KOTOAMATSUKAMIDistinguished Heavenly Gods KOTOAMATSUKAMI Data 4 decembrie 2020 20:37:15
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.07 kb
#include <bits/stdc++.h>
using namespace std;

class InParser {
private:
    FILE *fin;
    char *buff;
    int sp;

    char read_ch() {
        ++sp;
        if (sp == 4096) {
            sp = 0;
            fread(buff, 1, 4096, fin);
        }
        return buff[sp];
    }

public:
    InParser(const char* nume) {
        fin = fopen(nume, "r");
        buff = new char[4096]();
        sp = 4095;
    }

    InParser& operator >> (int &n) {
        char c;
        while (!isdigit(c = read_ch()) && c != '-');
        int sgn = 1;
        if (c == '-') {
            n = 0;
            sgn = -1;
        } else {
            n = c - '0';
        }
        while (isdigit(c = read_ch())) {
            n = 10 * n + c - '0';
        }
        n *= sgn;
        return *this;
    }

    InParser& operator >> (unsigned long long &n) {
        char c;
        n = 0ull;
        while (!isdigit(c = read_ch()));

        n = c ^ '0';
        while (isdigit(c = read_ch()))
            n = (n << 3ull) + (n << 1ull) + (c ^ '0');
        return *this;
    }
};

#include <ext/pb_ds/assoc_container.hpp>
struct marijuana {
    static unsigned long long splitmix64(unsigned long long x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const {
        static const unsigned long long FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
}; __gnu_pbds::gp_hash_table <unsigned long long, char, marijuana> hashish;

int main(void) {
    unsigned long long n;
    InParser fin("dtcsu.in");

    int sex = 2276997;
    for (; sex; --sex) {
        fin >> n;
        hashish[n] = 1;
    }

    int ans = 0;
    for (fin >> sex; sex; --sex) {
        fin >> n;
        if (hashish[n >> __builtin_ctz(n)])
            ++ans;
    }

    fprintf(fopen("dtcsu.out", "w"), "%d", ans);
    return 0;
}