結果
問題 | No.649 ここでちょっとQK! |
ユーザー | komori3 |
提出日時 | 2022-07-29 03:53:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 10,204 bytes |
コンパイル時間 | 4,606 ms |
コンパイル使用メモリ | 283,028 KB |
実行使用メモリ | 214,768 KB |
最終ジャッジ日時 | 2024-07-18 18:20:50 |
合計ジャッジ時間 | 11,335 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,752 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 23 ms
5,376 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
#define _CRT_NONSTDC_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <random> #include <unordered_set> #include <atcoder/all> //#include <boost/rational.hpp> //#include <boost/multiprecision/cpp_int.hpp> //#include <boost/multiprecision/cpp_bin_float.hpp> #ifdef _MSC_VER #include <conio.h> #include <ppl.h> #include <filesystem> #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <intrin.h> int __builtin_clz(unsigned int n) { unsigned long index; _BitScanReverse(&index, n); return 31 - index; } int __builtin_ctz(unsigned int n) { unsigned long index; _BitScanForward(&index, n); return index; } namespace std { inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); } } #else #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif /** compro_io **/ /* tuple */ // out namespace aux { template<typename T, unsigned N, unsigned L> struct tp { static void output(std::ostream& os, const T& v) { os << std::get<N>(v) << ", "; tp<T, N + 1, L>::output(os, v); } }; template<typename T, unsigned N> struct tp<T, N, N> { static void output(std::ostream& os, const T& v) { os << std::get<N>(v); } }; } template<typename... Ts> std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t) { os << '['; aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t); return os << ']'; } template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x); /* pair */ // out template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return os << "[" << p.first << ", " << p.second << "]"; } // in template<class S, class T> std::istream& operator>>(std::istream& is, std::pair<S, T>& p) { return is >> p.first >> p.second; } /* container */ // out template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x) { bool f = true; os << "["; for (auto& y : x) { os << (f ? "" : ", ") << y; f = false; } return os << "]"; } // in template < class T, class = decltype(std::begin(std::declval<T&>())), class = typename std::enable_if<!std::is_same<T, std::string>::value>::type > std::istream& operator>>(std::istream& is, T& a) { for (auto& x : a) is >> x; return is; } std::ostream& operator<<(std::ostream& os, const std::vector<bool>& v) { std::string s(v.size(), ' '); for (int i = 0; i < v.size(); i++) s[i] = v[i] + '0'; os << s; return os; } std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<bool>>& m) { for (const auto& v : m) os << v << '\n'; return os; } /* struct */ template<typename T> auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) { out << t.stringify(); return out; } /* setup */ struct IOSetup { IOSetup(bool f) { if (f) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::cout << std::fixed << std::setprecision(15); } } iosetup(true); /** string formatter **/ template<typename... Ts> std::string format(const std::string& f, Ts... t) { size_t l = std::snprintf(nullptr, 0, f.c_str(), t...); std::vector<char> b(l + 1); std::snprintf(&b[0], l + 1, f.c_str(), t...); return std::string(&b[0], &b[0] + l); } template<typename T> std::string stringify(const T& x) { std::ostringstream oss; oss << x; return oss.str(); } /* dump */ #define DUMPOUT std::cerr std::ostringstream DUMPBUF; #define dump(...) do{DUMPBUF<<" ";DUMPBUF<<#__VA_ARGS__<<" :[DUMP - "<<__LINE__<<":"<<__FUNCTION__<<"]"<<std::endl;DUMPBUF<<" ";dump_func(__VA_ARGS__);DUMPOUT<<DUMPBUF.str();DUMPBUF.str("");DUMPBUF.clear();}while(0); void dump_func() { DUMPBUF << std::endl; } template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPBUF << head; if (sizeof...(Tail) == 0) { DUMPBUF << " "; } else { DUMPBUF << ", "; } dump_func(std::move(tail)...); } ///* timer */ //class Timer { // double t = 0, paused = 0, tmp; //public: // Timer() { reset(); } // static double time() { //#ifdef _MSC_VER // return __rdtsc() / 3.0e9; //#else // unsigned long long a, d; // __asm__ volatile("rdtsc" // : "=a"(a), "=d"(d)); // return (d << 32 | a) / 3.0e9; //#endif // } // void reset() { t = time(); } // void pause() { tmp = time(); } // void restart() { paused += time() - tmp; } // double elapsed_ms() const { return (time() - t - paused) * 1000.0; } //} timer; /* rand */ struct Xorshift { uint64_t x = 88172645463325252LL; void set_seed(unsigned seed, int rep = 100) { x = uint64_t((seed + 1) * 10007); for (int i = 0; i < rep; i++) next_int(); } unsigned next_int() { x = x ^ (x << 7); return x = x ^ (x >> 9); } unsigned next_int(unsigned mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % mod; } unsigned next_int(unsigned l, unsigned r) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % (r - l + 1) + l; } // inclusive double next_double() { return double(next_int()) / UINT_MAX; } } rnd; /* shuffle */ template<typename T> void shuffle_vector(std::vector<T>& v, Xorshift& rnd) { int n = v.size(); for (int i = n - 1; i >= 1; i--) { int r = rnd.next_int(i); std::swap(v[i], v[r]); } } /* split */ std::vector<std::string> split(std::string str, const std::string& delim) { for (char& c : str) if (delim.find(c) != std::string::npos) c = ' '; std::istringstream iss(str); std::vector<std::string> parsed; std::string buf; while (iss >> buf) parsed.push_back(buf); return parsed; } template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } template<typename T, typename ...Args> auto make_vector(T x, int arg, Args ...args) { if constexpr (sizeof...(args) == 0)return std::vector<T>(arg, x); else return std::vector(arg, make_vector<T>(x, args...)); } template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } //using ll = long long; //using ull = unsigned long long; //using ld = double; ////using ld = boost::multiprecision::cpp_bin_float_quad; //using pii = std::pair<int, int>; //using pll = std::pair<ll, ll>; //using namespace std; template<typename T> void print_vector(const std::vector<T>& v) { for (int i = 0; i < v.size(); i++) { std::cout << (i ? " " : "") << v[i]; } std::cout << '\n'; } // 後で template 化 template<typename T> //using T = int; struct SortedMultiSet { SortedMultiSet(std::vector<T> a = {}) { std::sort(a.begin(), a.end()); build(a); } void add(const T& x) { if (!m_size) { m_a = { {x} }; m_size = 1; return; } auto& a = find_bucket(x); size_t i = std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x)); // upper bound? a.insert(a.begin() + i, x); m_size++; if (a.size() > m_a.size() * REBUILD_RATIO) build(); } bool discard(const T& x) { if (!m_size) return false; auto& a = find_bucket(x); size_t i = std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x)); if (i == a.size() || a[i] != x) return false; a.erase(a.begin() + i); m_size--; if (a.empty()) build(); return true; } size_t index(const T& x) const { size_t ans = 0; for (const auto& a : m_a) { if (a.back() >= x) { return ans + std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x)); } ans += a.size(); } return ans; } size_t index_right(const T& x) const { size_t ans = 0; for (const auto& a : m_a) { if (a.back() > x) { return ans + std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x)); } ans += a.size(); } return ans; } size_t count(const T& x) const { return index_right(x) - index(x); } const T& operator[] (size_t x) const { for (const auto& a : m_a) { if (x < a.size()) return a[x]; x -= a.size(); } assert(false); return m_a.back().back(); } inline size_t size() const { return m_size; } private: static constexpr size_t BUCKET_RATIO = 50; static constexpr size_t REBUILD_RATIO = 170; std::vector<std::vector<T>> m_a; size_t m_size = 0; void build(const std::vector<T>& a_ = {}) { std::vector<T> a; if (a_.empty()) { a.reserve(m_size); for (const auto& v : m_a) for (const auto& x : v) a.push_back(x); } else a = a_; m_size = a.size(); size_t bucket_size = size_t(ceil(sqrt(double(m_size) / BUCKET_RATIO))); for (size_t i = 0; i < bucket_size; i++) { m_a.emplace_back(a.begin() + m_size * i / bucket_size, a.begin() + m_size * (i + 1) / bucket_size); } } std::vector<T>& find_bucket(const T& x) { for (auto& a : m_a) { if (x <= a.back()) return a; } return m_a.back(); } }; int main() { using ll = long long; int Q, K; std::cin >> Q >> K; SortedMultiSet<ll> ss; for (int i = 0; i < Q; i++) { int t; std::cin >> t; if (t == 1) { ll v; std::cin >> v; ss.add(v); } else { if (ss.size() < K) { std::cout << -1 << '\n'; } else { ll v = ss[K - 1]; std::cout << v << '\n'; ss.discard(v); } } } return 0; }