Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 300100;
- const int M = 1000100;
- const int oo = 2e9;
- const int PW = 20;
- const int md = int(1e9) + 7;
- bool cmp(int a,int b){
- return a<b;
- }
- int main()
- {
- int n;
- cin>>n;
- vector<int> a(n);
- vector<int> last_el(1);
- vector<int> col(n);
- for(int i=0;i<n;i++){
- long long t;
- cin>>t;
- a[i]=t;
- }
- last_el[0]=-oo;
- for(int i=0;i<n;i++){
- long long length=last_el.end()-last_el.begin();
- int h=lower_bound(last_el.begin(),last_el.end(),a[i],cmp)-last_el.begin();
- if(h!=length){
- if(h==length-1){
- last_el.push_back(a[i]);
- col[i]=h+2;
- }
- else{
- last_el[h+1]=a[i];
- a[i]=h+1;
- }
- }
- else{
- last_el[0]=a[i];
- col[i]=1;
- }
- }
- cout<<last_el.end()-last_el.begin()<<endl;
- for(int i=0;i<n;i++){
- cout<<col[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement