結果
問題 | No.670 log は定数 |
ユーザー |
![]() |
提出日時 | 2018-03-23 22:47:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,417 bytes |
コンパイル時間 | 2,796 ms |
コンパイル使用メモリ | 194,708 KB |
実行使用メモリ | 786,304 KB |
最終ジャッジ日時 | 2024-06-24 22:14:07 |
合計ジャッジ時間 | 30,133 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | MLE * 10 |
ソースコード
#include "bits/stdc++.h"using namespace std;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }template<typename T, typename Func>void countingSort(int n, const T v[], T dest[], int cnt[/*B*/], int B, Func f) {if (n <= (B >> 4) || n <= 16) {memcpy(dest, v, sizeof(T) * n);std::stable_sort(dest, dest + n, [f](const T &a, const T &b) -> bool { return f(a) < f(b); });return;}for (int j = 0; j < B; ++ j)cnt[j] = 0;for (int i = 0; i < n; ++ i)++ cnt[f(v[i])];for (int j = 1; j < B; ++ j)cnt[j] += cnt[j - 1];for (int i = n - 1; i >= 0; -- i)dest[-- cnt[f(v[i])]] = v[i];}int main() {int N; int Q; unsigned long long seed;while (~scanf("%d%d%llu", &N, &Q, &seed)) {auto next = [&seed]() {seed = seed ^ (seed << 13);seed = seed ^ (seed >> 7);seed = seed ^ (seed << 17);return (int)(seed >> 33);};rep(i, 10000) next();vector<int> A(N), tmp(N);rep(i, N) A[i] = next();int cnt[1 << 11];countingSort(N, A.data(), tmp.data(), cnt, 1 << 11, [](int x) { return x & 0x7ff; });A.swap(tmp);countingSort(N, A.data(), tmp.data(), cnt, 1 << 10, [](int x) { return x >> 11 & 0x3ff; });A.swap(tmp);countingSort(N, A.data(), tmp.data(), cnt, 1 << 10, [](int x) { return x >> 21 & 0x3ff; });A.swap(tmp);vector<pair<int, int>> X(Q), tmp2(Q);rep(qi, Q) X[qi] = { next(), qi };countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 11, [](pair<int, int> x) { return x.first & 0x7ff; });X.swap(tmp2);countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 10, [](pair<int, int> x) { return x.first >> 11 & 0x3ff; });X.swap(tmp2);countingSort(Q, X.data(), tmp2.data(), cnt, 1 << 10, [](pair<int, int> x) { return x.first >> 21 & 0x3ff; });X.swap(tmp2);ll anssum = 0;{int ai = 0;for (auto q : X) {for (; ai < N && A[ai] < q.first; ++ ai);anssum ^= (ll)ai * q.second;}}printf("%lld\n", anssum);}return 0;}