#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,a[maxN],e[maxN];
deque<ll>vec[maxN];
void solve()
{
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i];
ll m=0;
for(int i=1;i<=n;i++)
{
ll x=lower_bound(e+1,e+m+1,a[i])-e;
if(x>m) m++;
vec[x].pb(i);
e[x]=a[i];
}
vector<vector<ll>> ans;
while(vec[m].size()>0)
{
bool ok=true;
ll v=vec[m].front();
vec[m].pop_front();
ll cur=v;
for(int i=m-1;i>=1;i--)
{
while(vec[i].size()>0&&a[vec[i].front()]>a[v])
{
vec[i].pop_front();
}
if(vec[i].size()==0) ok=false;
}
if(ok)
{
vector<ll> cc;
cc.pb(v);
for(int i=m-1;i>=1;i--)
{
cc.pb(vec[i].front());
vec[i].pop_front();
}
reverse(cc.begin(),cc.end());
ans.pb(cc);
}
}
cout << ans.size()<<' '<<m<<'\n';
for(auto zz:ans)
{
for(auto vc:zz) cout << vc<<' ';
cout << '\n';
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
Main.cpp:11:14: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
11 | const ll inf=1e18;
| ^~~~
Main.cpp: In function 'void solve()':
Main.cpp:34:12: warning: unused variable 'cur' [-Wunused-variable]
34 | ll cur=v;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |