Skip to content

Commit 32e86a8

Browse files
authored
Create 2019-H-A.cpp
1 parent 4c39b7d commit 32e86a8

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

kick-start/2019-H-A.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include<bits/stdc++.h>
2+
#include<bits/extc++.h>
3+
#define ms(x,v) memset((x),v,sizeof(x))
4+
#define INF 0x3f3f3f3f
5+
using namespace std;
6+
using namespace __gnu_pbds;
7+
8+
const int MAXN = 100+10;
9+
typedef long long LL;
10+
11+
typedef tree<pair<LL,int>,
12+
null_type,
13+
less<pair<LL,int>>,
14+
rb_tree_tag,
15+
tree_order_statistics_node_update> ordered_tree;
16+
17+
18+
19+
20+
void solve(){
21+
int n;
22+
cin >> n;
23+
vector<int> a(n);
24+
for(int i=0 ; i<n ; ++i)
25+
cin >> a[i];
26+
27+
ordered_tree se;
28+
vector<int> ans(n);
29+
ans[0] =1;
30+
se.insert(make_pair(a[0],0));
31+
32+
// const auto ok = [se](int h){
33+
// cout << h << "\n";
34+
// cout << se.size() <<" " << se.order_of_key(make_pair(h-1,INF)) <<"\n";
35+
// return se.size() - se.order_of_key(make_pair(h-1,INF)) >= h;
36+
// };
37+
for(int i=1 ; i<n ; ++i){
38+
se.insert(make_pair(a[i],se.size()));
39+
40+
int left = ans[i-1]-1;
41+
int right = i+1;
42+
// if(i==5 )
43+
// for(const auto & e : se)
44+
// cout << e.first << " "<< e.second << "\n";
45+
while(left <= right){
46+
int mid = (left + right) >>1;
47+
bool ok = se.size() - se.order_of_key(make_pair(mid-1,INF)) >= mid;
48+
if(ok)left = mid +1;
49+
else right = mid -1;
50+
}
51+
ans[i] = left - 1;
52+
}
53+
for(int i=0 ; i<n ; ++i)
54+
cout << " " << ans[i];
55+
cout << '\n';
56+
}
57+
58+
59+
60+
61+
62+
int main(){
63+
ios :: sync_with_stdio(0);
64+
cin.tie(0);
65+
// cout.tie(0);
66+
std::cout.precision(10);
67+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
68+
int T;
69+
cin >> T;
70+
for(int tt =1 ; tt <=T ; ++tt)
71+
{
72+
cout << "Case #" << tt << ": ";
73+
solve();
74+
}
75+
return 0;
76+
}

0 commit comments

Comments
 (0)