20251004总结
前言
这次考的还不错,但是被 int128 背刺少了
分数:
题目
小鸡(chick)
水题,容易发现每次交换逆序对数量的奇偶性不变,记个逆序对即可。
小L过河(river)
神秘数学题,被int128肘击了。
我们可以将式子转化一下:
我们可以枚举
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 10, MOD = 1e9 + 7;
int T, n, xa, ca, xb, cb;
map<int, int> mp;
void print(__int128 x){
if(!x){
return ;
}
print(x / 10);
cout << (int)(x % 10);
}
void solve(){
cin >> n >> xa >> ca >> xb >> cb;
if(xb == 1){
n--;
cout << (n % xa ? -1 : n / xa * ca) << '\n';
return ;
}
__int128 ans = -1;
for(__int128 i = 0, j = 1; j <= n; i++, j *= xb){
__int128 m = n - j, w = i * cb;
if(m % xa){
continue;
}
//cout << m << ' ';
m /= xa;
//cout << i << ' ' << w << ' ' << j << ' ' << m << ' ';
for(__int128 k = i, op = j; k >= 0; op /= xb, k--){
if(m >= op){
__int128 p = m / op;
m -= p * op, w += p * ca;
}
}
//cout << w << ' ' << m << '\n';
if(m == 0){
ans = (ans == -1 ? w : min(w, ans));
}
}
if(ans == -1){
cout << "-1\n";
return ;
}
if(ans == 0){
cout << "0\n";
return ;
}
print(ans);
cout << '\n';
}
signed main(){
// freopen("river.in", "r", stdin);
// freopen("river.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> T >> T;
while(T--){
solve();
}
return 0;
}
黑哥的序列(sequence)
我们可以先
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n;
long long a[N], dp[N], mx, mn;
int main(){
//freopen("sequence.in", "r", stdin);
//freopen("sequence.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
bool fl = 1;
for(int i = 1; i <= n; i++){
cin >> a[i];
fl &= a[i] >= a[i - 1];
}
if(fl){
cout << (a[n] - a[1]) * (a[n] - a[1]) << '\n';
return 0;
}
for(int i = 1; i <= n; i++){
mx = -1e18, mn = 1e18;
for(int j = i; j >= 1 && abs(j - i) <= 15; j--){
mx = max(a[j], mx), mn = min(mn, a[j]);
dp[i] = max(dp[i], dp[j - 1] + (mx - mn) * (mx - mn));
}
}
cout << dp[n];
return 0;
}