# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
862238 | AbdelmagedNour | Volontiranje (COCI21_volontiranje) | C++17 | 224 ms | 92456 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int a[n],lis[n]={};
for(int i=0;i<n;i++)cin>>a[i];
vector<int>dp;
for(int i=0;i<n;i++){
auto it=upper_bound(dp.begin(),dp.end(),a[i]);
if(it==dp.end())dp.push_back(a[i]);
else *it=a[i];
lis[i]=upper_bound(dp.begin(),dp.end(),a[i])-dp.begin();
}
int mx=dp.size();
vector<vector<int>>lvl(mx+1);
for(int i=0;i<n;i++)lvl[lis[i]].push_back(i);
for(int i=1;i<=mx;i++)reverse(lvl[i].begin(),lvl[i].end());
vector<vector<int>>ans;
vector<int>cur;
while(!lvl[1].empty()||!cur.empty()){
if(cur.empty())cur.push_back(lvl[1].back()),lvl[1].pop_back();
else if(cur.size()==mx)ans.push_back(cur),cur.clear();
else{
int nxt=cur.size()+1;
while(!lvl[nxt].empty()&&lvl[nxt].back()<cur.back())lvl[nxt].pop_back();
if(!lvl[nxt].empty()&&a[lvl[nxt].back()]>a[cur.back()])cur.push_back(lvl[nxt].back()),lvl[nxt].pop_back();
else cur.pop_back();
}
}
cout<<ans.size()<<" "<<mx<<"\n";
for(auto v:ans){
for(auto x:v)cout<<x+1<<" ";
cout<<"\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |