結果
問題 |
No.670 log は定数
|
ユーザー |
![]() |
提出日時 | 2018-03-23 22:58:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,286 bytes |
コンパイル時間 | 2,506 ms |
コンパイル使用メモリ | 203,480 KB |
最終ジャッジ日時 | 2025-01-05 09:23:16 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | MLE * 10 |
コンパイルメッセージ
main.cpp:60:32: warning: ‘template<class _Arg, class _Result> struct std::unary_function’ is deprecated [-Wdeprecated-declarations] 60 | struct get_key_t : public std::unary_function<val_t,key_type> | ^~~~~~~~~~~~~~ In file included from /usr/include/c++/13/string:49, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from main.cpp:1: /usr/include/c++/13/bits/stl_function.h:117:12: note: declared here 117 | struct unary_function | ^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; typedef int key_type; template <int UNIT, int BITS, class RAI, class G> void radix_sort(RAI a0, RAI aN, G get_key) { typedef typename std::iterator_traits<RAI>::value_type val_t; typedef typename std::iterator_traits<RAI>::difference_type dif_t; typedef typename G::result_type key_type; static const int KEYS = 1 << UNIT; static const int MASK = KEYS - 1; const dif_t N = aN - a0; const RAI& a = a0; if (N < 2) return; std::vector<dif_t> h(KEYS); std::vector<val_t> b(N); const typename std::vector<val_t>::iterator b0 = b.begin(); const typename std::vector<val_t>::iterator bN = b.end(); for (int shift = 0; shift < BITS; shift += UNIT) { for (int k = 0; k < KEYS; k++) h[k] = 0; typename std::vector<val_t>::iterator bi = b0; bool done = true; for (RAI ai = a0; ai < aN; ++ai, ++bi) { const val_t& x = *ai; const key_type y = get_key(x) >> shift; if (y > 0) done = false; ++h[int(y & MASK)]; *bi = x; } if (done) return; for (int k = 1; k < KEYS; k++) h[k] += h[k - 1]; for (bi = bN; bi > b0;) { const val_t& x = *(--bi); const int y = int((get_key(x) >> shift) & MASK); const dif_t j = --h[y]; a[j] = x; } } } ull seed; inline int next() { seed = seed ^ (seed << 13); seed = seed ^ (seed >> 7); seed = seed ^ (seed << 17); return (seed >> 33); } struct val_t { key_type key; int data; }; struct get_key_t : public std::unary_function<val_t,key_type> { key_type operator()(const val_t& x) const { return x.key; } }; int main() { int n, q; cin >> n >> q >> seed; for (int i = 0; i < 10000; i++) next(); vector<int> a(n); for (int i = 0; i < n; i++) a[i] = next(); sort(begin(a), end(a)); a.push_back(INT_MAX); ll sm = 0; vector< val_t > rad(q); for (int i = 0; i < q; i++) { rad[i].key = next(); rad[i].data = i; } radix_sort<8,32>(rad.begin(), rad.end(), get_key_t()); int ptr = 0; for(int i = 0; i < q; i++) { auto& p = rad[i]; while(a[ptr] < p.key) ++ptr; sm ^= ll(ptr) * p.data; } cout << sm << endl; }