Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- profile.h
- #pragma once
- #include <iostream>
- #include <chrono>
- using namespace std;
- using namespace std::chrono;
- class LogDuration
- {
- public:
- explicit LogDuration(const string& msg = "") : message(msg + ": "), start(steady_clock::now())
- {
- }
- ~LogDuration()
- {
- auto finish = steady_clock::now();
- auto dur = finish - start;
- cerr << message << duration_cast<milliseconds>(dur).count() << " ms" << endl;
- }
- private:
- string message;
- steady_clock::time_point start;
- };
- #define UNIQ_ID_IMPL(lineno) _a_local_var_##lineno
- #define UNIQ_ID(lineno) UNIQ_ID_IMPL(lineno)
- #define LOG_DURATION(message) LogDuration UNIQ_ID(__LINE__) { message };
- #####################################################################################################################
- main
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <set>
- #include "profile.h"
- using namespace std;
- int main()
- {
- LOG_DURATION("Total");
- ifstream in("input.txt");
- int element_count;
- in >> element_count;
- set<int> elements;
- {
- LOG_DURATION("Input");
- for (int i = 0; i < element_count; ++i)
- {
- int x;
- in >> x;
- elements.insert(x);
- }
- }
- int query_count;
- in >> query_count;
- int total_found = 0;
- {
- LOG_DURATION("Queries processing");
- for (int i = 0; i < query_count; ++i)
- {
- int x;
- in >> x;
- if (elements.find(x) != elements.end())
- {
- ++total_found;
- }
- }
- }
- cout << total_found << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement