forked from SayanKar/CPP-CODES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructing_an_array.cpp
More file actions
73 lines (73 loc) · 1.62 KB
/
constructing_an_array.cpp
File metadata and controls
73 lines (73 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
vector<int> longest_subsequence(int a[],int n)
{
int start=0,max=0,idx=0,eidx=0,start_idx=0,end_idx=0;
for(int i=0;i<n;i++)
{
//cout<<"he1\n";
if(a[i]==0)
{//cout<<"he2\n";
if(start>0)
{
start++;
if(max<start)
{//cout<<"he3\n";
max=start;
idx=start_idx;
eidx=i;
}
}
else
{//cout<<"he4\n";
start_idx=i;
start++;
if(max<start)
{//cout<<"he3\n";
max=start;
idx=start_idx;
eidx=i;
}
}
}
else{
start=0;
}
}
//cout<<"he5\n";
vector<int> ans;
ans.push_back(idx);
ans.push_back(eidx);
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
a[i]=0;
}
vector<int> ans;
for(int i=0;i<n;i++)
{
//cout<<"he\n";
ans=longest_subsequence(a,n);
// cout<<"he6\n";
//cout<<"for "<<i<<"th iteration the initial index="<<ans[0]<<"the final index is "<<ans[1]<<"\n";
int idx=(ans[0]+ans[1])/2;
//cout<<ans[0]<<" "<<ans[1]<<"\n";
a[idx]=i+1;
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}cout<<"\n";
}
return 0;
}