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>
#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=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll dp[maxN];
ll id[maxN],n;
pli b[maxN];
ll a[maxN],par[maxN];
ll get(ll l,bool p)
{
dp[0]=0;
id[0]=0;
for(int i=1;i<=n;i++)
{
dp[i]=-inf;
ll L=i-l;
ll R=i-b[i].fi;
if(R>=0&&id[R]>=L)
{
dp[i]=dp[id[R]]+1;
par[i]=id[R];
}
id[i]=id[i-1];
if(dp[i]>=dp[id[i]]) id[i]=i;
}
if(p)
{
vector<vector<ll>>ans;
ll x=n;
while(x!=0)
{
vector<ll>vd;
vd.pb(x-par[x]);
for(int i=par[x]+1;i<=x;i++)
{
vd.pb(b[i].se);
}
ans.pb(vd);
x=par[x];
}
for(auto zz:ans)
{
for(auto xx:zz)
{
cout << xx<<' ';
}
cout << '\n';
}
}
return dp[n];
}
void solve()
{
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i],b[i]={a[i],i};
sort(b+1,b+n+1);
ll low=0,high=n;
ll x=get(n,0);
while(low<=high)
{
ll mid=low+high>>1;
if(get(mid,0)==x) high=mid-1;
else low=mid+1;
}
cout << x<<'\n';
get(low,1);
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
tea.cpp: In function 'void solve()':
tea.cpp:69:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | ll mid=low+high>>1;
| ~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |