T1
#include <fstream>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const ll kMaxN = 3e7 + 5;
ifstream cin("A.in");
ofstream cout("A.out");
ll n, A, B, C, u[kMaxN], v[kMaxN], w[kMaxN], maxh[kMaxN];
i128 ans = 0;
ull Rand(ull &k1, ull &k2) {
ull k3 = k1, k4 = k2;
k1 = k4;
k3 ^= (k3 << 23);
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
void GetData() {
ull x, y;
cin >> n >> A >> B >> C >> x >> y;
for (ll i = 1; i <= n; i++) {
u[i] = Rand(x, y) % A + 1;
v[i] = Rand(x, y) % B + 1;
w[i] = Rand(x, y) % C + 1;
if (Rand(x, y) % 3 == 0) {
u[i] = A;
}
if (Rand(x, y) % 3 == 0) {
v[i] = B;
}
if ((u[i] != A) && (v[i] != B)) {
w[i] = C;
}
}
}
void prll(i128 x) {
if (x >= 10) {
prll(x / 10);
}
cout.put(x % 10 + '0');
}
int main() {
GetData();
ll maxn = 0;
for (ll i = 1; i <= n; ++i) {
if (u[i] == A && v[i] == B) {
maxn = max(maxn, w[i]);
}
}
ans = (i128)A * B * maxn;
for (ll h = C; h > maxn; --h) {
for (ll i = 1; i <= n; ++i) {
if (w[i] == h) {
maxh[u[i]] = max(maxh[u[i]], v[i]);
}
}
for (ll i = A; i >= 1; --i) {
maxh[i] = max(maxh[i], maxh[i + 1]);
}
for (ll i = 1; i <= A; ++i) {
ans += maxh[i];
}
}
prll(ans);
return 0;
}
T2
#include <cstring>
#include <fstream>
using namespace std;
using ll = long long;
const int kMaxN = 305, kMod = 1e9 + 7;
ifstream cin("B.in");
ofstream cout("B.out");
ll n, p[kMaxN], pw[kMaxN][kMaxN], dp[kMaxN][kMaxN];
int main() {
cin >> n;
for (int i = 1; i < n; ++i) {
cin >> p[i];
pw[i][0] = 1;
for (int j = 1; j <= n; ++j) {
pw[i][j] = (ll)pw[i][j - 1] * (1 - p[i] + kMod) % kMod;
}
}
int ans = 0;
for (int r = 1; r <= n; ++r) {
memset(dp, 0, sizeof(dp));
dp[1][r] = 1;
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= n - i + 1; ++j) {
if (j) {
dp[i + 1][j - 1] = (dp[i + 1][j - 1] + (ll)dp[i][j] * (1 - pw[i][j - 1] + kMod) % kMod) % kMod;
}
if (j < n - i + 1) {
dp[i + 1][j] = (dp[i + 1][j] + (ll)dp[i][j] * pw[i][j] % kMod) % kMod;
}
}
}
ans = (ans + (ll)dp[n][1] * r % kMod) % kMod;
}
cout << ans;
return 0;
}
T3
简单小清新分治。
#include <fstream>
using namespace std;
const int kMaxN = 1e6 + 1;
ifstream cin("C.in");
ofstream cout("C.out");
int n, ans, a[kMaxN], b[kMaxN], c[kMaxN];
void Solve(int l, int r) {
if (l >= r) {
if (l == r) {
c[a[l]]--;
}
return;
}
bool f = 0;
int pos = -1;
for (int i = l, j = r; i <= j; i++, j--) {
// cout << i << ' ' << j << ' ' << c[a[i]] << ' ' << c[a[j]] << '\n';
if (c[a[i]] < b[r - l + 1]) {
pos = i;
break;
}
if (c[a[j]] < b[r - l + 1]) {
pos = j, f = 1;
break;
}
}
if (pos > 0) {
if (f) {
for (int i = pos; i <= r; i++) {
c[a[i]]--;
}
Solve(l, pos - 1);
for (int i = pos + 1; i <= r; i++) {
c[a[i]]++;
}
Solve(pos + 1, r);
} else {
for (int i = l; i <= pos; i++) {
c[a[i]]--;
}
Solve(pos + 1, r);
for (int i = l; i < pos; i++) {
c[a[i]]++;
}
Solve(l, pos - 1);
}
} else {
for (int i = 1; i <= n; i++) {
c[a[i]]--;
}
// cout << r - l + 1 << '\n';
ans = max(ans, r - l + 1);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c[a[i]]++;
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
Solve(1, n);
cout << ans << '\n';
return 0;
}
标签:总结,10.7,int,ll,cin,kMaxN,long,using
From: https://www.cnblogs.com/GenesisCrystal/p/18459807