Serie: Algorithms
cpp
55 líneas
· Actualizado 2026-04-07
8402.cpp
Algorithms/8402.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 5;
int arr[MAXN];
int freq[MAXN];
long long suf[MAXN];
void generateArray(int* arr, int n, int m, int seed) {
unsigned x = seed;
for (int i = 1; i <= n; i++) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
arr[i] = x % m + 1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, seed;
cin >> n >> m >> seed;
generateArray(arr, n, m, seed);
// 計算頻率
for (int i = 1; i <= n; i++) {
freq[arr[i]]++;
}
// suffix sum: suf[x] = count of numbers >= x
for (int i = m; i >= 1; i--) {
suf[i] = suf[i + 1] + freq[i];
}
long long ans = 0;
for (int x = 1; x <= m; x++) {
long long c = suf[x];
if (c == 0) continue;
// 找最大 2^k ≤ c
long long p = 1;
while (p * 2 <= c) p *= 2;
ans = max(ans, p * x);
}
cout << ans << "\n";
return 0;
}
Artículos relacionados
Algorithms
java
Actualizado 2026-03-02
#include <iostream>.java
#include <iostream>.java — java source code from the Algorithms learning materials (Algorithms/#include <iostream>.java).
Leer artículo →
Algorithms
cpp
Actualizado 2026-04-07
748.cpp
748.cpp — cpp source code from the Algorithms learning materials (Algorithms/748.cpp).
Leer artículo →
Algorithms
cpp
Actualizado 2026-04-07
827.cpp
827.cpp — cpp source code from the Algorithms learning materials (Algorithms/827.cpp).
Leer artículo →
Algorithms
cpp
Actualizado 2026-04-07
827_best_greedy.cpp
827_best_greedy.cpp — cpp source code from the Algorithms learning materials (Algorithms/827_best_greedy.cpp).
Leer artículo →
Algorithms
cpp
Actualizado 2026-04-07
860.cpp
860.cpp — cpp source code from the Algorithms learning materials (Algorithms/860.cpp).
Leer artículo →
Algorithms
cpp
Actualizado 2026-07-24
bin_packing.cpp
bin_packing.cpp — cpp source code from the Algorithms learning materials (Algorithms/Advanced/bin_packing.cpp).
Leer artículo →