CF1990B Array Craft
Departure_ · · 题解
Array Craft
给定三个整数
n,x,y (x>y ),构造一个长度为n 的序列a 满足:
- 满足
\sum_{j=1}^i a_j=\max_{j=1}^{n}\sum_{k=1}^j a_k 的最小索引i=x 。- 满足
\sum_{j=i}^n a_j=\max_{j=1}^{n}\sum_{k=j}^n a_k 的最大索引i=y 。
我们记
接下来,
最后,
时间复杂度
#include<iostream>
#include<algorithm>
#include<cassert>
#include<bitset>
#include<list>
#include<iomanip>
#ifdef ONLINE_JUDGE
#define getchar() (_p==_q&&(_q=(_p=_b)+fread(_b,1,_s,stdin),_p==_q)?-1:*_p++)
#define putchar(x) ((_r-_o<_s)?(*_r++=x):(flush(),_r=_o,*_r++=x))
#endif
#define inline inline __attribute__((__always_inline__))
#define flush() fwrite(_o,_r-_o,1,stdout),fflush(stdout)
using namespace std;const int _s=1<<20;char _b[_s],_o[_s],*_p=_b,*_q=_b,*_r=_o;template<class T>inline bool fr(T&x){x=0;char c=0;bool f=0;do{if((c=getchar())==-1)return 0;if(c=='-')f=1;}while(c<48||c>57);do {x=x*10+c-48;if((c=getchar())==-1)break;}while(c>47&&c<58);if(f)x=-x;return 1;}template<class T>inline void fw(T x){char _d[40],_l=-1;if(x<0)x=-x,putchar('-');do _d[++_l]=x%10+48;while(x/=10);do putchar(_d[_l]);while(~--_l);}
#define int long long
const int maxn=2e5+3;
int n,x,y,a[maxn];
signed main(){
// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cerr.tie(0);
// freopen("2.in","r",stdin);
// freopen("2.out","w",stdout);
int cse;fr(cse);while(cse--){
fr(n),fr(x),fr(y);
for(int i=y;i<=x;i++)a[i]=1;
for(int i=y-1;i>=1;i--)a[i]=a[i+1]*-1;
for(int i=x+1;i<=n;i++)a[i]=a[i-1]*-1;
for(int i=1;i<=n;i++)fw(a[i]),putchar(32);
putchar(10);
}
flush(),exit(0);
}