CF1793B题解
题意
定义一个长为
定义局部最大值为与其相邻的元素都小于它的数,局部最小值为与其相邻的元素都大于它的数。
给出一个序列的局部最大值之和
思路
设第
为了让
此时有一种显然的构造方法:
代码:
#include <bits/stdc++.h>
using namespace std;
long long t, x, y;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t--) {
cin >> x >> y;
if(x > y)
swap(x, y);
cout << 2 * abs(x - y) << '\n' << x << ' ';
for(long long i = x + 1; i < y; i++)
cout << i << ' ';
for(long long i = y; i > x; i--)
cout << i << ' ';
cout << '\n';
}
return 0;
}