蒟蒻求助
查看原帖
蒟蒻求助
478585
Dregen_Yor楼主2022/8/15 13:04

很奇怪,85分,subtask2全WA,求助大佬

#include <cstdio> // scanf
#include <bits/stdc++.h>
#define int unsigned long long
const int MAXN = 1e7 + 10; // Set a right value according to your solution.
int n, w[MAXN + 1];
using namespace std;
namespace Generator {

	unsigned long long k1, k2;
	int thres;

	inline unsigned long long xorShift128Plus() {
		unsigned long long k3 = k1, k4 = k2;
		k1 = k4, k3 ^= (k3 << 23), k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
		return k2 + k4;
	}

	inline void generate() {
		for (int i = 1; i <= n; ++i) {
			w[i] = xorShift128Plus() % thres;
		}
	}

} // namespace Generator.

signed main() {
	scanf("%lld", &n);
	scanf("%llu%llu%lld", &Generator::k1, &Generator::k2, &Generator::thres);
	Generator::generate();
	int s = n, head = 1, m = 0x7fffffff;
	while (head < n) {
		s = head;m = w[head];
		for (int i = head; i <= n; i++) {
			if (m >= w[i]) {
				m = w[i];
				s = i;
			}
		}
		swap(w[head],w[s]);
		head=s+1;
	}
	unsigned long long ans = 0ull;
	for (unsigned long long i = 1; i <= n; i++) {
		ans += w[i] * i;
	}
	printf("%llu", ans);
	return 0;
}
2022/8/15 13:04
加载中...