-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
45 lines (43 loc) · 950 Bytes
/
C.cpp
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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[100005];
int main()
{
fastio;
long long t,n,i,low,high,mid;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
cout<<1<<" ";
for(i=1;i<n;i++)
{
if(i+1<=ara[0])
{
cout<<i+1<<" ";
continue;
}
low=1;
high=i;
while(low<=high)
{
mid=(low+high)/2;
if(ara[mid]>=i-mid+1 && ara[mid-1]<i-mid+2)
{
cout<<i-mid+1<<" ";
break;
}
else if(ara[mid]>=i-mid+1)
high=mid-1;
else
low=mid+1;
}
}
cout<<"\n";
}
return 0;
}