Pagini recente » Cod sursa (job #1779011) | Cod sursa (job #923400) | Cod sursa (job #42842) | Cod sursa (job #2144318) | Cod sursa (job #1778194)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
unsigned int st,dr,nr,x,m,n,i,j,maxbest,v[100001],best[100001],previ[100001],current[100001];
int main()
{
f>>n;
for(i=1;i<=n;i++) f>>v[i];
maxbest=0; best[0]=0;
for(i=1;i<=n;i++) best[i]=1<<31;
for(i=1;i<=n;i++)
{
if(v[i]<best[maxbest])
{
st=0; dr=maxbest;
while(st<dr)
{
m=(st+dr)/2;
if(best[m]<v[i]) st=m+1;
else dr=m-1;
}
while(best[st]>=v[i]) st--;
if(best[st+1]>v[i])
{
best[st+1]=v[i];
current[st+1]=i;
previ[st+1]=current[st];
}
cout<<1<<' '<<current[st+1]<<' '<<previ[st+1]<<'\n';
}
else if(v[i]>best[maxbest])
{
best[++maxbest]=v[i];
current[maxbest]=i;
previ[maxbest]=current[maxbest-1];
cout<<2<<' '<<current[maxbest]<<' '<<previ[maxbest]<<'\n';
}
}
g<<maxbest<<'\n';
//for(i=1;i<=maxbest;i++) g<<best[i]<<' ';
nr=1;
for(i=1;i<=n && nr<=maxbest;i++)
{
if(v[i]<=best[nr] && v[i]>x)
{
x=v[i];
g<<v[i]<<' ';
nr++;
}
}
return 0;
}