結果

問題 No.670 log は定数
ユーザー merom686merom686
提出日時 2018-03-23 23:45:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,147 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 85,600 KB
実行使用メモリ 394,820 KB
最終ジャッジ日時 2023-09-07 04:32:13
合計ジャッジ時間 11,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

using ll = long long;
using ull = unsigned long long;

ull seed;
int next() {
    seed = seed ^ (seed << 13);
    seed = seed ^ (seed >> 7);
    seed = seed ^ (seed << 17);
    return (seed >> 33);
}

pair<int, int> *pii;

template <class I>
void radix_sort(I first, I last) {
    using T = typename std::iterator_traits<I>::value_type;
    constexpr int L = 16, M = 1 << L, K = 2;

    size_t n = last - first;
    T *p[2] = { &*first, pii };
    size_t m[M];

    std::fill_n(m, M, 0);
    for (size_t i = 0; i < n; i++) {
        m[(p[0][i].first & M - 1)]++;
    }
    for (int j = M - 1; j > 0; j--) {
        m[j] = m[j - 1];
    }
    m[0] = 0;
    for (int j = 2; j < M; j++) {
        m[j] += m[j - 1];
    }
    for (size_t i = 0; i < n; i++) {
        T t = p[0][i];
        p[1][m[t.first & M - 1]++] = t;
    }
    std::swap(p[0], p[1]);
    std::fill_n(m, M, 0);
    for (size_t i = 0; i < n; i++) {
        m[(p[0][i].first >> L)]++;
    }
    for (int j = M - 1; j > 0; j--) {
        m[j] = m[j - 1];
    }
    m[0] = 0;
    for (int j = 2; j < M; j++) {
        m[j] += m[j - 1];
    }
    for (size_t i = 0; i < n; i++) {
        T t = p[0][i];
        p[1][m[t.first >> L]++] = t;
    }
    std::swap(p[0], p[1]);
}

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(a.begin(), a.end());

    ll r = 0;
    int q2 = q / 2;
    pii = (pair<int, int> *)std::malloc(q2 * sizeof(pair<int, int>));
    vector<pair<int, int>> x(q2);
    for (int l = 0; l < 2; l++) {
        for (int h = 0; h < q2; h++) {
            x[h] = { next(), h + l * q2 };
        }
        radix_sort(x.begin(), x.end());
        ll k = 0;
        for (int h = 0; h < q2; h++) {
            while (k < n && a[k] < x[h].first) k++;
            r ^= k * x[h].second;
        }
    }

    cout << r << endl;

    return 0;
}
0