2025.1.16——1200
2025.1.16——1200
Q1. 1200
You are given
In other words, the score of a permutation is the sum of
You need to find the maximum possible score among all permutations of length
For example, if
Input
The only line of each test case description contains
Q2. 1200
You are given two arrays of integers —
After all the operations, the value of
Above,
Input
The first line of each test case contains two integers
The second line of each test case contains
The third line of each test case contains
------------------------思考------------------------
-
数学/结论+位运算
A1
- 发现结论:除了共有的位置,计算个数分别分配最大值与最小值。
- 共有的位置是最小公倍数占的位置。
A2
- 位运算:保存
数组的每一位,相当于将原异或和值的某一位进行 互换。 - 奇数时可使原值变大,偶数时可使原值减小。
------------------------代码------------------------
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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, x, y;
cin >> n >> x >> y;
int hasx = n / x, hasy = n / y;
int hasxy = n / (x * y / __gcd(x, y));
hasx -= hasxy;
hasy -= hasxy;
// bug3(hasx, hasy, hasxy);
auto get = [](int st, int ed)
{
int cnt = ed - st + 1;
return (st + ed) * cnt / 2;
};
cout << get(n - hasx + 1, n) - get(1, hasy) << 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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
int _xor = 0;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
_xor ^= x;
}
map<int, bool> has_bit;
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
for (int j = 0; x >> j; j++)
if (x >> j & 1) // wa
has_bit[j] = 1;
}
int mx = _xor, mn = _xor;
if (n & 1)
{
for (auto [bit, has] : has_bit)
{
if (mx >> bit & 1)
;
else
mx += 1ll << bit; //, bug(bit);
// bug(mx);
}
}
else
{
for (auto [bit, has] : has_bit)
if (mn >> bit & 1)
mn -= 1ll << bit;
}
cout << mn << ' ' << mx << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!