結果
問題 | No.702 中央値を求めよ LIMITED |
ユーザー | xuzijian629 |
提出日時 | 2018-09-05 14:41:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,210 bytes |
コンパイル時間 | 660 ms |
コンパイル使用メモリ | 77,368 KB |
最終ジャッジ日時 | 2025-01-01 22:24:15 |
合計ジャッジ時間 | 1,123 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:20:1: error: ‘uint32_t’ does not name a type 20 | uint32_t x = 0, y = 1, z = 2, w = 3; | ^~~~~~~~ main.cpp:11:1: note: ‘uint32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? 10 | #include <cassert> +++ |+#include <cstdint> 11 | #pragma GCC optimize("O3") main.cpp:21:1: error: ‘uint32_t’ does not name a type 21 | uint32_t generate() { | ^~~~~~~~ main.cpp:21:1: note: ‘uint32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? main.cpp: In function ‘int main()’: main.cpp:31:5: error: ‘uint32_t’ was not declared in this scope 31 | uint32_t seed; | ^~~~~~~~ main.cpp:31:5: note: ‘uint32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? main.cpp:32:12: error: ‘seed’ was not declared in this scope 32 | cin >> seed; | ^~~~ main.cpp:33:5: error: ‘x’ was not declared in this scope 33 | x = seed; | ^ main.cpp:35:20: error: template argument 2 is invalid 35 | vector<uint32_t> tmp, reserved; | ^ main.cpp:38:13: error: request for member ‘push_back’ in ‘tmp’, which is of non-class type ‘int’ 38 | tmp.push_back(generate()); | ^~~~~~~~~ main.cpp:38:31: error: no matching function for call to ‘generate()’ 38 | tmp.push_back(generate()); | ~~~~~~~~^~ In file included from /usr/include/c++/13/algorithm:61, from main.cpp:4: /usr/include/c++/13/bits/stl_algo.h:4434:5: note: candidate: ‘template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)’ 4434 | generate(_ForwardIterator __first, _ForwardIterator __last, | ^~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:4434:5: note: template argument deduction/substitution failed: main.cpp:38:31: note: candidate expects 3 arguments, 0 pro
ソースコード
#include <iostream> #include <vector> #include <array> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <map> #include <unordered_map> #include <cassert> #pragma GCC optimize("O3") #pragma comment(linker, "STACK:36777216") using namespace std; using i64 = int64_t; constexpr i64 MOD = 1e9 + 7; using vi = vector<i64>; using vvi = vector<vi>; using vvvi = vector<vvi>; uint32_t x = 0, y = 1, z = 2, w = 3; uint32_t generate() { uint32_t t = (x^(x<<11)); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); return w; } int main() { uint32_t seed; cin >> seed; x = seed; vector<uint32_t> tmp, reserved; int tmpsize = 1000001; for (int i = 0; i < tmpsize; i++) { tmp.push_back(generate()); } sort(tmp.begin(), tmp.end()); for (int i = 250000; i <= 750000; i++) { reserved.push_back(tmp[i]); } double off = 0; int small_cnt = 0; uint32_t min = reserved.front(), max = reserved.back(), mid = reserved[250000]; for (int i = 0; i < 9; i++) { assert(reserved.size() == 500001); for (int j = 0; j < 1000000; j++) { uint32_t u1 = generate(); if (u1 <= mid) { off -= 0.5; if (u1 > min) { small_cnt++; reserved.push_back(u1); } } if (u1 > mid) { off += 0.5; if (u1 < max) { reserved.push_back(u1); } } } sort(reserved.begin(), reserved.end()); assert(mid == reserved[250000 + small_cnt]); int new_mid_ind = 250000 + small_cnt + int(off); // cout << new_mid_ind << " " << reserved.size() << endl; tmp.clear(); for (int k = new_mid_ind - 250000; k <= new_mid_ind + 250000; k++) { assert(k >= 0 && k < reserved.size()); tmp.push_back(reserved[k]); } reserved = vector<uint32_t>(tmp); mid = reserved[250000]; min = reserved.front(); max = reserved.back(); off = 0; small_cnt = 0; } cout << mid << endl; }