#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
vector<array<int,2>> tree(4*N,{0,0});
void update(int idx,int l,int r,int pos,int x)
{
if(l==r) tree[idx]={x,pos};
else
{
int m=(l+r)/2;
if(pos<=m) update(2*idx,l,m,pos,x);
else update(2*idx+1,m+1,r,pos,x);
tree[idx]=max(tree[2*idx],tree[2*idx+1]);
}
}
array<int,2> query(int idx,int l,int r,int ql,int qr)
{
if(ql>qr) return {-1,0};
if(l==ql&&r==qr) return tree[idx];
int m=(l+r)/2;
return max(query(2*idx,l,m,ql,min(qr,m)),query(2*idx+1,m+1,r,max(ql,m+1),qr));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<array<int,2>> a(n+1,{0,0});
for(int i=1;i<=n;i++)
{
cin >> a[i][0];
a[i][1]=i;
}
sort(a.begin(),a.end());
vector<int> p(n+1,0);
auto go=[&](int lim)->int
{
int t=0;
update(1,0,n,0,0);
for(int i=1;i<=n;i++)
{
auto [x,j]=query(1,0,n,max(0,i-lim),i-a[i][0]);
if(x==-1) update(1,0,n,i,-1);
else
{
update(1,0,n,i,x+1);
p[i]=j;
t=x+1;
}
}
for(int i=1;i<=4*n;i++) tree[i]={-1,0};
return t;
};
int cnt=go(n);
int l=0,r=n;
while(l<r-1)
{
int m=(l+r)/2;
if(go(m)==cnt) r=m;
else l=m;
}
cout << cnt << "\n";
int idx=n;
while(idx>=1)
{
cout << idx-p[idx] << " ";
for(int i=p[idx]+1;i<=idx;i++) cout << a[i][1] << " \n"[i==idx];
idx=p[idx];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31564 KB |
Output is correct |
2 |
Correct |
13 ms |
31564 KB |
Output is correct |
3 |
Incorrect |
14 ms |
31564 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
31564 KB |
Output is correct |
2 |
Correct |
13 ms |
31608 KB |
Output is correct |
3 |
Correct |
14 ms |
31544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31564 KB |
Output is correct |
2 |
Correct |
17 ms |
31564 KB |
Output is correct |
3 |
Correct |
15 ms |
31636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
31712 KB |
Output is correct |
2 |
Correct |
28 ms |
31716 KB |
Output is correct |
3 |
Correct |
31 ms |
31712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
31648 KB |
Output is correct |
2 |
Correct |
31 ms |
31720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
373 ms |
33420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
526 ms |
33704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2561 ms |
44012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2562 ms |
49164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2580 ms |
50192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |