A. Submission Bait
思路:
如果最大值有奇数个显然Alice赢,否则只需要看排序后是否存在n−i+1是否为奇数且ai>ai−1即可。
代码:
#include<bits/stdc++.h>
using namespace std;
#define N 2000010
typedef long long ll;
typedef unsigned long long ull;
ll n, m, h, k, t, x, y, z;
ll a, b, c, d, mod = 998244353;
ll ans, num, sum1=0, sum, sum2=0, cnt, maxx, minn = 1e9;
ll f1[N], f2[N], dp[N], an[N];
bool flag, vis[N];
string s,s1,s2;
map<ll, ll>mp;
bool cmp(ll x, ll y) {
return x > y;
}
//void solve() {
// cin >> n >> x >> y;
//
// if (x >= y) {
// for (int i = 1; i <= n; i++) {
// if(dp[i]>=x&&)
// }
// }
// else {
// for (int i = x + 1; i < y; i++)
// dp[i] = -1;
// }
// for (int i = 1; i <= n; i++)
// cout << dp[i] << " ";
// cout << endl;
//}
void solve() {
int n;
cin >> n;
vector<int>a(n);
vector<int>vis(55);
for (int i = 0; i < n; i++) cin >> a[i], vis[a[i]]++;
sort(a.begin(), a.end());
int mx = a[n - 1];
int ans = 0;
for (int i = n - 1; i >= 0; i--)
if (a[i] == mx) ans++;
if (ans % 2 == 1)
{
cout << "YES\n";
return;
}
for (int i = n; i >= 1; i--)
{
if (vis[i] % 2 == 1) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main()
{
cin >> t;
while (t--) {
solve();
}
}
B. Array Craft
思路:
可以确定x和y这两个位置一定是1且x+1和y-1一定是-1,不难想到可以把y到x之间全填1,两边1和-1交叉填即可.
代码:
#include<bits/stdc++.h>
using namespace std;
#define N 2000010
typedef long long ll;
typedef unsigned long long ull;
ll n, m, h, k, t, x, y, z;
ll a, b, c, d, mod = 998244353;
ll ans, num, sum1=0, sum, sum2=0, cnt, maxx, minn = 1e9;
ll f1[N], f2[N], dp[N], an[N];
bool flag, vis[N];
string s,s1,s2;
map<ll, ll>mp;
bool cmp(ll x, ll y) {
return x > y;
}
void solve() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
if (i >= y && i <= x) {
dp[i] = 1;
}
}
for (int i = y-1; i >=1;i-=2) {
dp[i] = -1, dp[i - 1] = 1;
}
for (int i = x + 1; i <= n; i += 2) {
dp[i] = -1, dp[i + 1] = 1;
}
for (int i = 1; i <= n; i++)
cout << dp[i] << " ";
cout << endl;
}
int main()
{
cin >> t;
while (t--) {
solve();
}
}
C. Mad MAD Sum
思路:
通过模拟可知:第一次操作后,数组中出若干个数字块,且呈升序,其中注意到第一次操作后会有个别的长度为1的数字块.
我们发现从第二次操作开始,每个长度 >= 2的数字块都会向右滑动一位,而第一次操作出现的长度为1的数字块都会被覆盖掉
也就是说,两次操作后就是整个数组向右不断移动的过程,模拟完前两轮依次删除最后一个数,统计贡献即可
代码:
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define N 200010
typedef long long ll;
typedef unsigned long long ull;
ll n, m, h, k, t, x, y, z;
ll a, b, c, d, mod = 998244353;
ll ans, num, sum1=0, sum, sum2=0, maxx, minn = 1e9;
ll f1[N], f2[N], dp[N], an[N],cnt[N];
bool flag, vis[N];
string s,s1,s2;
map<ll, ll>mp;
vector<ll>aa(N);
bool cmp(ll x, ll y) {
return x > y;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> dp[i];
}
sum = 0;
for (int i = 1; i <= 2; i++) {
maxx = 0;
memset(vis, 0, sizeof(vis));
for (int j = 1; j <= n; j++) {
if (vis[dp[j]])
maxx = max(maxx, dp[j]);
vis[dp[j]] = true;
sum += dp[j];
dp[j] = maxx;
}
}
for (int i = 1; i <= n; i++) {
sum += (n - i + 1) * dp[i];
}
cout << sum << endl;
}
int main()
{
cin >> t;
while (t--) {
solve();
}
}