NBC006- Editorial

PROBLEM LINK:

Practice
Noob Coding Contest

Author: sourav472
Tester: sourav472
Editorialist: sourav472

DIFFICULTY:

EASY

PREREQUISITES:

Basic Array operation

EXPLANATION:

You are given an array (A1,A2,A3……AN) of length N. Your task is to find an another array using the given array according to the conditions given in the question:
For example, the 1st element of the output array will be the sum of A1 and (A1)th element if A1 is less equal N.
Other wise you have to follow the steps below:
i) Divide the value of A1 by 2 untill it will be less than N.
ii) then find D=(N-A1).
iii) finally, the 1st element of the output array will be the Dth element.
The rest elements of the output array will be found by following the above procedure

SOLUTIONS:

Setter's Solution & Tester's Solution
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define dfor(i,a,b) for(ll i=(a);i<(b);i++)
#define rfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define pii pair<ll,ll>
#define vi vector<ll>
#define vpii vector<pii>
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define fast ios_base::sync_with_stdio( false );cin.tie(NULL);
const ll mod = (ll)(1e9+7); 
int main() {
    fast
    ll t;
    cin>>t;
	while(t--)
	{ 
	  ll n;
	  cin>>n;
	  ll a[n+1],i;
	  for(i=1;i<=n;i++)
	    cin>>a[i];
	   
	  for(i=1;i<=n;i++)
                   {
	    if(a[i]>n){
	        ll p = a[i];
	        while(p>=n){
	           p = p/2; 
	        }
	    cout<<a[n-p]<<" ";
	    }
	    else
	    cout<<a[a[i]]+a[i]<<" ";
	}
	cout<<"\n";
    }
	return 0;
}