CF1758D Range = √Sum 题解
首先的首先,我们肯定会将钦定
首先我们希望得到的数列很好构造(也就是很特殊),于是我们可能想到设
于是我们得到
我们有可能想到构造等差数列(应为
但是我们可以考虑等差数列公式是怎么得到的,是不是
那我们为什么要构造等差数列呢?只要满足
于是我们想出构造
注意一下,如果 a[(n+1)/2]=4n;
#include <bits/stdc++.h>
using namespace std;
#define il inline
const int N=3e5+5;
int n,a[N];
il void solve() {
cin>>n;
a[1]=3*n,a[n]=5*n;
if(n&1)a[(n+1)/2]=4*n;
for(int l=2,r=n-1;l<r;l++,r--) {
a[l]=a[l-1]+1,a[r]=a[r+1]-1;
}
for(int i=1;i<=n;i++)cout<<a[i]<<' ';cout<<'\n';
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T;cin>>T;while(T--)solve();
return 0;
}