2024.12.27 周五
2024.12.27 周五
Q1. 1100
Alex is participating in the filming of another video of BrMeast, and BrMeast asked Alex to prepare 250 thousand tons of TNT, but Alex didn't hear him well, so he prepared
All trucks that Alex is going to use hold the same number of boxes, denoted by
- The first
boxes goes to the first truck, - The second
boxes goes to the second truck, - The last
boxes goes to the -th truck.
Upon loading is completed, each truck must have exactly
Alex hates justice, so he wants the maximum absolute difference between the total weights of two trucks to be as great as possible. If there is only one truck, this value is
Alex has quite a lot of connections, so for every
Q2. 1100
You are given an array
There are
After all modification queries, you need to output the final array.
------------------------独自思考分割线------------------------
-
这两道题都和数学有些关系,暴力会超时,通过数学与前缀优化解决。
A1.
- 读懂题就是:对于每个可被n整除的数作为一个长度k,对每个长度将n分为n/k连续的块,问块和的最大差值。
- 因数最多为
,前缀和优化,时间复杂度 。 - 初始化最大值上界开小了(区间和),wa一发。
A2.
- 若要被
整除,其后 位需要全为 ,加上 后,再次遇到 就不会有贡献,即需要发现的点是q数组中的数只有第一次出现才会有贡献,因此最多 个,两层暴力即可。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> pre(n + 1);
for (int i = 1; i <= n; i++)
cin >> pre[i], pre[i] += pre[i - 1];
auto ask = [&](int l, int r)
{
return pre[r] - pre[l - 1];
};
vector<int> op;
for (int i = 1; i <= n; i++)
if (n % i == 0)
op.push_back(i);
int res = 0;
auto get = [&](int d)
{
int l = 1, r = d;
int maxw = 0, minw = 1e18;
while (r <= n)
{
maxw = max(maxw, ask(l, r));
minw = min(minw, ask(l, r));
l+=d,r+=d;
}
return maxw - minw;
};
for (auto d : op)
res = max(res, get(d));
cout << res << endl;
}
A2.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int &x : a)
cin >> x;
int has[31] = {}; // map自动排序 无法保证原始序列
vector<int> b;
while (q--)
{
int x;
cin >> x;
if (!has[x])
b.push_back(x);
has[x] = 1;
}
for (auto &x : b)
for (auto &a : a)
{
int v = 1ll << x;
// bug(v);
a += a % v == 0 ? (v >> 1) : 0;
}
for (auto v : a)
cout << v << ' ';
cout << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!