結果

問題 No.702 中央値を求めよ LIMITED
ユーザー xuzijian629xuzijian629
提出日時 2018-09-05 14:41:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 570 ms / 5,000 ms
コード長 2,210 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 91,076 KB
実行使用メモリ 13,388 KB
最終ジャッジ日時 2024-05-02 09:48:03
合計ジャッジ時間 17,617 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 568 ms
13,188 KB
testcase_01 AC 537 ms
13,132 KB
testcase_02 AC 554 ms
13,260 KB
testcase_03 AC 570 ms
13,388 KB
testcase_04 AC 534 ms
13,132 KB
testcase_05 AC 537 ms
13,128 KB
testcase_06 AC 522 ms
13,260 KB
testcase_07 AC 532 ms
13,132 KB
testcase_08 AC 516 ms
13,264 KB
testcase_09 AC 526 ms
13,240 KB
testcase_10 AC 540 ms
13,260 KB
testcase_11 AC 563 ms
13,260 KB
testcase_12 AC 542 ms
13,256 KB
testcase_13 AC 547 ms
13,260 KB
testcase_14 AC 546 ms
13,244 KB
testcase_15 AC 541 ms
13,260 KB
testcase_16 AC 532 ms
13,132 KB
testcase_17 AC 519 ms
13,256 KB
testcase_18 AC 530 ms
13,136 KB
testcase_19 AC 528 ms
13,260 KB
testcase_20 AC 528 ms
13,260 KB
testcase_21 AC 545 ms
13,132 KB
testcase_22 AC 517 ms
13,156 KB
testcase_23 AC 543 ms
13,132 KB
testcase_24 AC 509 ms
13,384 KB
testcase_25 AC 538 ms
13,260 KB
testcase_26 AC 530 ms
13,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0