题解:拿笔画他的行走路线,你会发现可以前缀和预处理一些东西出来。
const int N = 300005; int n; ll a[N], b[N], dp[2][N], sp[2][N], sum[N]; int get_a() { dp[0][0] = 0; for (int i = 1; i < n; ++i) { dp[0][i] = dp[0][i - 1] + 1ll * i * a[i]; } int t = n; dp[1][n - 1] = dp[0][n - 1] + 1ll * t * b[n - 1]; for (int i = n - 2; ~i; --i) { t++; dp[1][i] = dp[1][i + 1] + 1ll * t * b[i]; } } int get_b() { sp[1][0] = b[1]; for (int i = 1; i < n; ++i) sp[1][i] = sp[1][i - 1] + 1ll * (i + 1) * b[i]; int t = n + 1; sp[0][n - 1] = sp[1][n - 1] + 1ll * t * a[n - 1]; for (int i = n - 2; ~i; --i) { t++; sp[0][i] = sp[0][i + 1] + 1ll * t * a[i]; } } void Inite() { for (int i = n - 1; ~i; --i) sum[i] = sum[i + 1] + a[i] + b[i]; } void solve() { ll ans = max(dp[1][0], sp[0][1]); int last = 0; ll tp = 0; for (int i = 0; i < n; ++i) { if(!last) { tp += 1ll * 2 * i * a[i] + 1ll * (2 * i + 1) * b[i]; if(i + 1 != n) ans = max(ans, tp + 1ll * i * sum[i + 1] + sp[0][i + 1] - sp[1][i]); } else { tp += 1ll * 2 * i * b[i] + 1ll * (2 * i + 1) * a[i]; if(i + 1 != n) ans = max(ans, tp + 1ll * (i + 1) * sum[i + 1] + dp[1][i + 1] - dp[0][i]); } last ^= 1; } printf("%I64d\n", max(ans, tp)); }
题解:可以这么构造,除了第一行,第一列填上以外,其它的行和列都填0,所以主要是算map[1][1]改填几,或者填最后一行和最后一列。
ans[n][m] = b[m] ^ (x ^ a[n]);
原文地址:https://www.cnblogs.com/zgglj-com/p/9419553.html
时间: 2024-10-07 17:10:16