白哥很黑模拟赛总结
我又没开long long!
预期:100 + 100 + 24 + 40
实际:100 + 100 + 4 + 32
T1
很快就想到了,但是写了1.5h。
题意:有一个长度为
正常人的想法是逆序对,但我不是正常人,所以我想到了链表。
可以发现,只要我从
那么我就判断一下
暴力移动是
我们发现将
于是可以用链表维护,注意当
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1e6 + 5;
int t, n, a[kMaxN], pre[kMaxN], nxt[kMaxN], ed;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (cin >> t; t; t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[a[i]] = a[i - 1];
nxt[a[i - 1]] = a[i];
}
nxt[a[n]] = 0;
ed = a[n];
for (int i = n; i >= 3; i--) {
if (!pre[i]) {
int x = nxt[nxt[i]];
pre[i] = x;
nxt[nxt[i]] = nxt[nxt[nxt[i]]];
pre[nxt[x]] = nxt[i];
nxt[x] = i;
pre[x] = 0;
}
if (i == ed) {
ed = pre[ed];
continue;
}
nxt[ed] = pre[i];
nxt[pre[pre[i]]] = nxt[i];
pre[nxt[i]] = pre[pre[i]];
nxt[i] = 0;
pre[pre[i]] = ed;
ed = pre[i];
}
cout << (pre[2] ? "Yes\n" : "No\n");
}
return 0;
}
T2
数学爽题,很好玩,写了1.5h。
题意:一个数,初始为 -1。
先特判一下
不难发现,乘的次数只有
这个
先处理一下初始的
而加操作只有
接下来我们再把
那么把
写完出去吃个包子,剩下55min,足够了。
#include <bits/stdc++.h>
#define int long long
using namespace std;
int c, t, n, x1, c1, x2, c2;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (cin >> c >> t; t; t--) {
cin >> n >> x1 >> c1 >> x2 >> c2;
if (x2 == 1) {
n--;
cout << (n % x1 ? -1 : (n / x1) * c1) << "\n";
continue;
}
int mn = 1e18, lim = 0;
for (__int128_t i = 1; i <= n; i *= x2, lim++);
for (int i = 0, x = n, y = 1; i < lim; i++, y *= x2, x = n) {
int sum = 0, ans = 0;
ans = i * c2;
x -= y;
if (x % x1)
continue;
x /= x1;
int ty = y;
for (int j = i; j >= 0; j--) {
sum += x / ty;
x %= ty;
ty /= x2;
}
mn = min(mn, ans + sum * c1);
}
cout << (mn == 1e18 ? -1 : mn) << "\n";
}
return 0;
}
T3
没开二度。
当时我竟然没有预料到它的答案会那么大,明明有平方。
预估24pts,实际4pts,开long long后40pts写完人类智慧100pts。
题意:给定一个长度为
显然最优方案的每个子段两端必然是最大值和最小值,所以
转移方程可以用李超线段树维护。
但是我不会,所以这里有另外一种能过的方法。
经过同学的实验,判掉特殊性质(单增),每个数只往前找
所以,我们充分发扬人类智慧:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kMaxN = 1e6 + 5;
int n, a[kMaxN], f[kMaxN];
signed main() {
cin >> n;
int flag = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < a[i - 1])
flag = 0;
}
if (flag)
cout << (a[n] - a[1]) * (a[n] - a[1]);
else {
for (int i = 1; i <= n; i++)
for (int j = max(1ll, i - 20); j <= i; j++)
f[i] = max(f[i], f[j - 1] + (a[i] - a[j]) * (a[i] - a[j]));
cout << f[n];
}
return 0;
}
T4
数据又骗人,本来20个测试点,每个有5pts,8个就有40pts,结果又有25个,只剩32pts。
题意:一棵
当
总结
我已经连续两次没开long long了🤬
上一次我吸取了同学的教训,于是我在今天空间足够的情况下 #define int long long,但是只有T2、4开了。
下次打框架就加上,我已经黑化了😈