Pagini recente » Cod sursa (job #2886660) | Cod sursa (job #1052977) | Cod sursa (job #2622892) | Cod sursa (job #2948298) | Cod sursa (job #1290710)
#include<fstream>
#include<iostream>
using namespace std;
ifstream f("secv6.in");
ofstream g("secv6.out");
int n,st[8193],i,zz,j,counter,k=0,a[8193];
int main(){
f>>n;
if(n>8192)
n=8192;
for(i=1;i<=n;i++){
f>>zz;
zz=i-1+(n^(zz%8192));
a[i]=zz;
if(k==0)
k++,st[k]=zz;
else
if(st[k]>zz)
k++,st[k]=zz;
else{
while(st[k]<=zz&&k>0)
k--,counter++;
if(k==0)
counter--;
k++,st[k]=zz;
if(k>1&&st[k-1]==st[k])
k--;
}
for(j=1;j<=k;j++)
cout<<st[j]<<" ";
cout<<'\n';
}
counter+=n-1;
for(i=1;i<=n;i++)
g<<a[i]<<" ";
g<<'\n';
g<<counter;
}