#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 mod=1e9+7;
ll n,a[maxN],e[maxN];
vector<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];
}
for(int i=1;i<=m;i++) reverse(vec[i].begin(),vec[i].end());
vector<vector<ll>> ans;
ll cnt=2;
while(vec[m].size())
{
bool ok=true;
ll v=vec[m].back();
vec[m].pop_back();
ll cur=v;
for(int i=m-1;i>=1;i--)
{
while(vec[i].size()>0&&a[vec[i].back()]>a[v])
{
vec[i].pop_back();
}
if(vec[i].size()>0&&vec[i].back()<v) v=vec[i].back();
else {ok=false;break;}
}
if(ok)
{
vector<ll> cc;
cc.pb(cur);
for(int i=m-1;i>=1;i--)
{
cc.pb(vec[i].back());
vec[i].pop_back();
}
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: In function 'void solve()':
Main.cpp:28:8: warning: unused variable 'cnt' [-Wunused-variable]
28 | ll cnt=2;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23712 KB |
Output is correct |
6 |
Correct |
12 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23760 KB |
Output is correct |
11 |
Correct |
11 ms |
23748 KB |
Output is correct |
12 |
Correct |
12 ms |
23728 KB |
Output is correct |
13 |
Correct |
12 ms |
23720 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23800 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
13 ms |
23824 KB |
Output is correct |
20 |
Correct |
12 ms |
23820 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23712 KB |
Output is correct |
6 |
Correct |
12 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23760 KB |
Output is correct |
11 |
Correct |
11 ms |
23748 KB |
Output is correct |
12 |
Correct |
12 ms |
23728 KB |
Output is correct |
13 |
Correct |
12 ms |
23720 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23800 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
13 ms |
23824 KB |
Output is correct |
20 |
Correct |
12 ms |
23820 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
15 ms |
23764 KB |
Output is correct |
25 |
Correct |
16 ms |
23708 KB |
Output is correct |
26 |
Correct |
13 ms |
23836 KB |
Output is correct |
27 |
Correct |
15 ms |
23812 KB |
Output is correct |
28 |
Correct |
13 ms |
23764 KB |
Output is correct |
29 |
Correct |
14 ms |
23840 KB |
Output is correct |
30 |
Correct |
12 ms |
23888 KB |
Output is correct |
31 |
Correct |
13 ms |
23784 KB |
Output is correct |
32 |
Correct |
13 ms |
23820 KB |
Output is correct |
33 |
Incorrect |
13 ms |
23764 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23712 KB |
Output is correct |
6 |
Correct |
12 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23760 KB |
Output is correct |
11 |
Correct |
11 ms |
23748 KB |
Output is correct |
12 |
Correct |
12 ms |
23728 KB |
Output is correct |
13 |
Correct |
12 ms |
23720 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
11 ms |
23764 KB |
Output is correct |
17 |
Correct |
13 ms |
23800 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
13 ms |
23824 KB |
Output is correct |
20 |
Correct |
12 ms |
23820 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
15 ms |
23764 KB |
Output is correct |
25 |
Correct |
16 ms |
23708 KB |
Output is correct |
26 |
Correct |
13 ms |
23836 KB |
Output is correct |
27 |
Correct |
15 ms |
23812 KB |
Output is correct |
28 |
Correct |
13 ms |
23764 KB |
Output is correct |
29 |
Correct |
14 ms |
23840 KB |
Output is correct |
30 |
Correct |
12 ms |
23888 KB |
Output is correct |
31 |
Correct |
13 ms |
23784 KB |
Output is correct |
32 |
Correct |
13 ms |
23820 KB |
Output is correct |
33 |
Incorrect |
13 ms |
23764 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |