-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistinctElements.cpp
More file actions
66 lines (63 loc) · 958 Bytes
/
DistinctElements.cpp
File metadata and controls
66 lines (63 loc) · 958 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
int freqcount(vector<int> &arr)
{
int freq=1;
int num = 1;
for(int i=1;i<arr.size();i++)
{
if(arr[i-1]!=arr[i])
{
num++;
}
freq+=num;
}
return freq;
}
void solve(vector<int> &arr)
{
int n = arr.size();
vector<int> ans(n);
ans[0]=n;
int temp = n;
for(int i=1;i<n;i++)
{
int count=1;
vector<int> build;
for(int j=i-1;j>=0;j--)
{
build.push_back(ans[j]);
}
count+=freqcount(build);
if(count<arr[i])
{
ans[i]=temp-1;
temp--;
}
else ans[i]=temp;
}
for(auto &x:ans)
cout<<x<<" ";
cout<<endl;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> arr(n);
for (auto &a:arr)
cin>>a;
solve(arr);
}
return 0;
}