-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpation_sort.cpp
More file actions
51 lines (51 loc) · 1.01 KB
/
pation_sort.cpp
File metadata and controls
51 lines (51 loc) · 1.01 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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,t,res;
vector<vector<int> >a;
void bs(int st,int en,int k){
if(st==en){
if(a[st][a[st].size()-1]>k)
res=min(res,(st+en+1)/2);
}
else if(st+1==en){
if(a[st][a[st].size()-1]>k)
res=min(res,(st+en+1)/2);
if(a[st+1][a[st+1].size()-1]>k)
res=min(res,(st+1+en+1)/2);
}
else{
if(a[(st+en+1)/2][a[(st+en+1)/2].size()-1]<=k)
bs((st+en+1)/2+1,en,k);
else
res=min(res,(st+en+1)/2),bs(st,(st+en+1)/2-1,k);
}
}
int main(){
cin>>n;
cin>>t;
a.resize(1);
a[0].push_back(t);
for(int i=1;i<n;i++){
cin>>t;
res=10000;
bs(0,a.size()-1,t);
if(res==10000){
a.resize(a.size()+1);
a[a.size()-1].push_back(t);
}
else
a[res].push_back(t);
}
/*for(int i=0;i<a.size();i++){
for(int j=0;j<a[i].size();j++)
cout<<a[i][j]<<" ";
cout<<endl;
}*/
int maxx=0;
for(auto &v:a)
maxx=max(a.size(),maxx);
cout<<maxx<<'\n';
return 0;
}