12月13号
Codeforces Round #772 (Div. 2)C题
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int a[N];
vector<int> v;
void solve()
{
int n;
cin >> n;
int flag = 1;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (i > 1 && a[i] < a[i - 1])
{
flag = 0;
}
}
if (flag)
{
cout << 0 << endl;
return;
}
if (a[n] < a[n - 1] || (a[n] < 0 && a[n - 1] < 0))
{
cout << "-1" << endl;
}
else
{
cout << n - 2 << endl;
for (int i = 1; i <= n - 2; i++)
{
cout << i << ' ' << n - 1 << ' ' << n << endl;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round #758 (Div.1 + Div. 2)B题
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int ans[N];
void solve()
{
int n, a, b;
cin >> n >> a >> b;
if (abs(a - b) > 1 || (a + b) > n - 2)
{
cout << -1 << endl;
return;
}
else
{
int i = 1, l = 1, r = n;
if (a == b)
{
while(i<=2*a) ans[i++]=l++,ans[i++]=r--;
for(;i<=n;) ans[i++]=l++;
}
else
{
if(a>b)
{
while(i<=2*b) ans[i++]=l++,ans[i++]=r--;
for(;i<=n;) ans[i++]=l++;
swap(ans[n-1],ans[n]);
}
else
{
while(i<=2*a) ans[i++]=r--,ans[i++]=l++;
for(;i<=n;) ans[i++]=r--;
swap(ans[n-1],ans[n]);
}
}
for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
cout<<endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
https://codeforces.com/problemset/problem/1592/B题
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int a[N], b[N];
void solve()
{
int n, x;
cin >> n >> x;
for (int i = 0; i < n; i++)
{
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
int flag = 1;
for (int i = n - x; i < x; i++)
{
if (a[i] != b[i])
{
flag = 0;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}