视频讲解~:Codeforces Round 959 (Div. 1 + Div. 2) A题-C题_哔哩哔哩_bilibili
讲解都在视频里(❁´◡`❁)
A - Diverse Game
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (auto &i : a)
for (auto &j : i)
cin >> j;
if (n == 1 && m == 1)
{
cout << -1 << endl;
continue;
}
if (n % 2 && m % 2)
swap(a[0][0], a[n / 2][m / 2]);
for (int i = n - 1; i >= 0; i--)
{
for (int j = m - 1; j >= 0; j--)
cout << a[i][j] << ' ';
cout << endl;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int n;
string s, t;
bool solve()
{
string temp(n, ' ');
for (int i = 0; i < n; i++)
temp[i] = (s[i] - '0') ^ (t[i] - '0') + '0';
int cnt1 = 0, cnt2 = 0;
for (auto i : temp)
{
if (i == '1')
break;
cnt1++;;
}
for (auto i : s)
{
if (i == '1')
break;
cnt2++;;
}
if (cnt2 > cnt1)
return false;
return true;
}
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> s >> t;
cout << (solve() ? "YES\n" : "NO\n");
}
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int T;
cin >> T;
while (T--)
{
int n, x, ans = 0;
cin >> n >> x;
vector<int> a(n), prefix(n), next(n), dp(n + 3, 0);
for (auto &i : a)
cin >> i;
prefix[0] = a[0];
for (int i = 1; i < n; i++)
prefix[i] = prefix[i - 1] + a[i];
for (int i = 0; i < n; i++)
{
int l = i - 1, r = n;
while (l + 1 < r)
{
int mid = (r + l) >> 1;
int curPrefix = (i == 0) ? prefix[mid] : prefix[mid] - prefix[i - 1];
if (curPrefix > x)
r = mid;
else
l = mid;
}
if (r == n)
next[i] = -1;
else
next[i] = r;
}
for (int i = n - 1; i >= 0; i--)
dp[i] = next[i] == -1 ? 0 : 1 + dp[next[i] + 1];
for (int i = 0; i < n; i++)
ans += n - i - dp[i];
cout << ans << endl;
}
}