Dashboard - Codeforces Round 900 (Div. 3) - Codeforces
C. Vasilije in Cacak
用等差数列求出能够构造出的最小值与最大值,判断x是否在这个范围内,如果在则能被构造出,此为结论,能被构造出的数为最小值与最大值之间的每一个数(如果有数小就往后移1)
一段数的和:(首项 + 末项) * 项数 / 2
cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int solve()
{
ll n, k, x, minn, maxx;
cin >> n >> k >> x;
minn = (1 + k) * k / 2;
maxx = (n - k + 1 + n) * k / 2;
if(x >= minn && x <= maxx)cout << "YES" << '\n';
else cout << "NO" << '\n';
}
int main()
{
int t;
cin >> t;
while(t --)
{
solve();
}
return 0;
}
D. Reverse Madness
将x看作一点,ri + li - x看作另一点,由于要翻转多次,可以每翻转一下记录一次,如果翻转了偶数次相当于没有翻转,不然就相当于翻转一次
cpp
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n, k, q, x;
string s;
cin >> n >> k;
cin >> s;
vector<int> l(k + 10, 0) , r(k + 10, 0), cnt (n + 1);
for(int i = 1; i <= k; i ++)
{
cin >> l[i];
l[i] --;
}
for(int i = 1; i <= k; i ++)
{
cin >> r[i];
r[i] --;
}
cin >> q;
while(q --)
{
cin >> x;
cnt[x - 1] ++;
}
for(int i = 1; i <= k; i ++)
{
int ll = l[i];
int rr = r[i];
int sum = 0;
for(int j = ll; j <= (ll + rr) / 2; j ++)
{
sum += cnt[j] + cnt[rr + ll - j];
if(sum & 1)swap(s[j], s[rr + ll -j]);
}
}
cout << s << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t --)
{
solve();
}
return 0;
}