Idea:Yugandhar_Master
If $$$n=1$$$, There is only one possible $$$\it{Lucky \ array}$$$. It is guaranteed that the given array is $$$\it{Lucky \ array}$$$ so there is no other $$$\it{Lucky \ array}$$$ to output. Hence the answer is $$$-1$$$.
For $$$n>1$$$, it is easy to see that there are more than one possible $$$\it{Lucky \ array}$$$. So we can use the following pattern to construct the $$$\it{Lucky \ array}$$$ :
$$$ 0 \ 1 \ 0 \ 1 \ 0 \ 1 \ ....$$$
If this constructed array is equal to the given array then we can swap the elements in $$$2^{nd}$$$ and $$$3^{rd}$$$ positions if $$$n>2$$$, otherwise we can just set the $$$2^{nd}$$$ to $$$0$$$.
Note that there are many possible constructions, the above mentioned is one of them
Time Complexity : $$$O(n)$$$.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int main(){
fast;
ll t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
if(n==1) cout<<"-1\n";
else if(n==2){
if(a[1]==1) cout<<"0 0\n";
else cout<<"0 1\n";
}
else{
vector<int> b(n,0);
for(int i=1;i<n;i+=2) b[i]=1;
if(a==b) swap(b[1],b[2]);
for(auto i:b) cout<<i<<" ";
cout<<"\n";
}
}
}
Idea:Yugandhar_Master
Coming soon...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int main(){
fast;
ll t;
cin>>t;
while(t--){
ll n,a,b;
cin>>n>>a>>b;
vector<ll> v(n);
for(ll i=0;i<n;i++) cin>>v[i];
ll l=0,r=1e9,ans=1e9;
while(l<=r){
ll m=(l+r)/2;
ll ops=0;
for(ll i=0;i<n;i++){
if(v[i]>b*m){
ops+=((v[i]-b*m+(a-b-1))/(a-b));
}
}
if(ops<=m){
ans=m;
r=m-1;
}
else l=m+1;
}
cout<<ans<<"\n";
}
}
Idea:Yugandhar_Master
Coming soon...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int main(){
fast;
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
vector<ll> a(n);
for(ll i=0;i<n;i++) cin>>a[i];
ll ans=0,val=1;
for(ll i=0;i<n;i++){
ll res=(a[i]-1)/val;
if(res>0){
ans+=res;
a[i]=1;
}
if(val==a[i]) val++;
}
ans++;
cout<<ans<<"\n";
}
}
Idea:wuhudsm
Coming soon...
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <bitset>
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
const int N=1000010;
const int LOGN=28;
const ll TMD=0;
const ll INF=2147483647;
int T;
ll n,m;
int tag[N];
int main()
{
//freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d",&n,&m);
ll mx=n*(n+1)/2-2,mn=-mx,sum=mn,cur1,cur2;
vector<ll> v[2];
if(m<mn||m>mx||((mx&1)^(m&1)))
{
printf("NO\n");
continue;
}
printf("YES\n");
tag[1]=1;
for(int i=2;i<=n;i++) tag[i]=0;
for(int i=2;i<=n;i++)
{
tag[i]=1;
sum+=2*i;
if(sum>=m)
{
tag[(sum-m)/2]=0;
break;
}
}
for(int i=1;i<=n;i++) v[tag[i]].push_back(i);
cur1=v[1][0];
for(int i=1;i<v[0].size();i++)
{
printf("%I64d %I64d\n",cur1,v[0][i]);
cur1-=v[0][i];
}
cur2=v[0][0];
for(int i=1;i<v[1].size();i++)
{
printf("%I64d %I64d\n",cur2,v[1][i]);
cur2-=v[1][i];
}
printf("%I64d %I64d\n",cur1,cur2);
}
//fclose(stdin);
return 0;
}
E: Mr.Wow and Hidden Permutation
Idea:Yugandhar_Master,wuhudsm
Coming soon...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int n;
vector<int> v1;
int query(vector<int> v){
cout<<"? ";
for(int i=0;i<(int)v.size();i++) cout<<v[i]+1<<" ";
cout<<endl;
int x;
cin>>x;
if(x>(n/2)) return 1;
return 0;
}
int sol(int j){
vector<int> v(n/2);
for(int i=0;i<n/2;i++) v[i]=v1[i+j];
return query(v);
}
int main(){
fast;
ll t;
cin>>t;
while(t--){
cin>>n;
v1.clear();
v1.resize(n);
for(int i=0;i<n;i++) v1[i]=i;
int l=0,r=n/2;
int vl=sol(0),vr=sol(n/2);
while(l+1<r){
int m=(l+r)/2;
int vm=sol(m);
if(vm==vl) l=m;
else r=m;
}
vector<int> v2,v3;
for(int i=r;i<(r+(n/2)-1);i++){
v2.push_back(v1[i]);
v3.push_back(v1[(i+(n/2))%n]);
}
vector<int> ans(n);
ans[v1[l]]=vl;
ans[v1[l+(n/2)]]=vr;
for(int i=0;i<(int)v2.size();i++){
vector<int> v=v3;
v.push_back(v2[i]);
ans[v2[i]]=query(v);
}
for(int i=0;i<(int)v3.size();i++){
vector<int> v=v2;
v.push_back(v3[i]);
ans[v3[i]]=query(v);
}
vector<int> even,odd;
for(int i=0;i<n;i++){
if(ans[i]==0) even.push_back(i+1);
else odd.push_back(i+1);
}
cout<<"! ";
for(int i=0;i<(int)even.size();i++){
cout<<even[i]<<" ";
cout<<odd[i]<<" ";
}
cout<<endl;
}
}
Idea:Yugandhar_Master
Coming soon...
~~~~~
~~~~~