版本比较
20251004总结
正文
增加 33 行删除 64 行
22 行未改动232425262727282930313210 行未改动4344454646474849505121 行未改动737475767677787980819 行未改动91929394949595969797989910010110210310410510610110710810310410911011110610710811211311411511611711811912012111011111211311411511611711811912212312412512112212312412512612712812913013112712812913013113213313413513613713813913214114214314414514613314714814915015115215315415515615715815916013413513616416516616722 行未改动$$
我们可以枚举 $m$,那么 $x_1$ 与 $x_2^m$ 就是已知的,减、除掉后我们又可以发现 $\sum_{i = 1}^{m} x_2^{m-i} \times a_i$ 可以化为一个 $x_2$ 进制数,那么我们就可以枚举 $m$ 算贡献了,时间复杂度 $O(\log ^ 2 V)$($x_2 = 1$ 时单独计算)。
```cpp```c#include<bits/stdc++.h>#include<bits/stdc++.h>
#define int long long
using namespace std;10 行未改动 print(x / 10); cout << (int)(x % 10);}
void solve(){ void solve(){ cin >> n >> xa >> ca >> xb >> cb; if(xb == 1){ n--; cout << (n % xa ? -1 : n / xa * ca) << '\n';21 行未改动 } if(ans == -1){ cout << "-1\n"; return ; } } if(ans == 0){ cout << "0\n"; return ; }9 行未改动 while(T--){ solve(); } return 0;}pp#include<bits/stdc++.h>}```
#define int long long## 黑哥的序列(sequence)
我们可以先 $O(n ^ 2)$ DP,然后人类智慧即可。
```cpp#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, MOD = 1e9 + 7;const int N = 1e6 + 5;
int T, n, xa, ca, xb, cb;map<int, int> mp;int n;long long a[N], dp[N], mx, mn;
void print(__int128 x){ if(!x){ return ;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]; } 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 ; if(fl){ cout << (a[n] - a[1]) * (a[n] - a[1]) << '\n'; return 0; } __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; 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 << 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"; cout << dp[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)
我们可以