結果

問題 No.670 log は定数
ユーザー antaanta
提出日時 2018-03-23 22:47:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,417 bytes
コンパイル時間 2,913 ms
コンパイル使用メモリ 192,496 KB
実行使用メモリ 786,184 KB
最終ジャッジ日時 2023-09-07 03:36:51
合計ジャッジ時間 29,665 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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