Cod sursa(job #2352168)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 23 februarie 2019 01:34:20
Problema A+B Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 4.65 kb
/*#include <fstream>
#include <bits/stdc++.h>
#include <thread>

#define DEBUG
#define SIGN

#define endl "\n"

#pragma GCC poison scanf printf qsort

#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
*/
/*class alignas(512) parser_faux{
public:
    static std::fstream in_file;
    static const int SIZE = BUFSIZ * 1024,
                     SECT_SIZE = 512;
    static int index, sign, sector;
    static char main_buffer[SIZE],
                aux_buffer[SECT_SIZE];
#ifdef DEBUG
    static constexpr auto inc = [&] () -> void { 
        if (++index == SECT_SIZE) {
            index &= 0;
            in_file.read(aux_buffer, SECT_SIZE);
            if (++sector == SIZE) {
                sector &= 0;
            }
        }
    };
#else
    void inc() {
        if (++index == SIZE) { 
            index &= 0;
            in_file.read(aux_buffer, SECT_SIZE);
            if (++sector == SIZE) {
                sector &= 0;
        }
    }
#endif /// DEBUG
public:
    parser () {
    } /// c-tor
    parser (const char *file_name) {
        in_file.open(file_name, std::ios_base::in | std::ios_base::binary),
        in_file.rdbuf() -> pubsetbuf(main_buffer, SIZE),
        in_file.sync_with_stdio(false),
        in_file.read(aux_buffer, SECT_SIZE),
        index &= 0,
        sector &= 0;
    }
    [[gnu::pure]] inline parser &operator >> (int &n) {
        for (; aux_buffer[index] < '0' and aux_buffer[index] > '9'; inc());
        n &= 0;
#ifdef SIGN
        sign &= 0,
        sign |= (aux_buffer[index - 1] == '-');
#endif /// SIGN
        for (; aux_buffer[index] >= '0' and aux_buffer[index] <= '9'; inc())
            n = (n << 3) + (n << 1) + aux_buffer[index] - '0';
#ifdef SIGN
        n ^= ((n ^ -n) & -sign);
#endif /// SIGN
        return *this;
    }
    ~parser () {
        in_file.close(); 
    } /// d-tor
};*/
/*
#pragma pack (push, 1)

class alignas(512) parser : public std::streambuf {
   public:
        explicit parser() { /// default c-tor
        /// Copyright Ciobanu Bogdan-Calin™ 2019
    }
        explicit parser(const char *file_name) {
           input_file.open(file_name, ios::in | ios::binary);
           input_file.sync_with_stdio(false);
           index &= 0;
           input_file.read(buffer, SIZE);
    } /// main-sequence c-tor
        [[gnu::hot]] inline parser &operator >> (int &n) {
            for (;buffer[index] < '0' or buffer[index] > '9'; inc());
            n &= 0;
            sign &= 0;
            sign |= (buffer[index - 1] == '-');
            for (;'0' <= buffer[index] and buffer[index] <= '9'; inc())
                n= 10 * n + buffer[index] - '0';
            n ^= ((n ^ -n) & -sign);
            return *this;
        }
        ~parser() {
            input_file.close();
        }
    private:
        fstream input_file;
        static const size_t SIZE = 0x400000, /// 4MB
                         SECT_SIZE = 4096;
        char main_buffer[SIZE],
             buffer[SECT_SIZE];
        int index, sign;
        inline void inc() {
            if(++index == SIZE)
                index=0,
                input_file.read(buffer, SIZE);
        }
};

#pragma pack (pop) 

int main() {
    parser f ("test.txt");
    int x;
    f >> x;
    cout << x << endl;
    return 0;
}
*/
#include <bits/stdc++.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

class parser {
public:
    
    explicit parser () {
        /// default c-tor
    }
    
    explicit parser (const char *file_name) {
        fd = open(file_name, O_RDONLY, 0),
        block_number &= 0,
        index &= 0,
        buffer = (char*) mmap(NULL, SIZE, PROT_READ, MAP_SHARED, fd, 0);
    }
    [[gnu::hot]] inline parser &operator >> (int &n) {
        for (;buffer[index] < '0' or buffer[index] > '9'; inc());
        n &= 0;
#ifdef SIGNED
        sign &= 0;
        sign |= (buffer[index - 1] == '-');
#endif
        for (;'0' <= buffer[index] and buffer[index] <= '9'; inc())
            n= 10 * n + buffer[index] - '0';
#ifdef SIGNED
        n ^= ((n ^ -n) & -sign);
#endif
        return *this;
    }
    ~parser () {
        munmap(buffer, SIZE);
        close(fd);
    }
private:
    static const int SIZE = 0x400000; /// 4MB
    int fd, block_number, index;
    char *buffer;
#ifdef SIGNED
    int sign;
#endif
    [[gnu::hot]] inline void inc() {
        if(++index == SIZE)
            index &= 0,
            ++block_number,
            buffer = (char*) mmap(NULL, SIZE, PROT_READ, MAP_SHARED, fd, block_number * SIZE);
    }
};

int main() {
    int x, y;
    std::ofstream t ("adunare.out");
    parser f ("adunare.in");
    f >> x >> y;
    t << x + y;
    return 0;
}