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>
using namespace std;
int steve[1000001],vf;
int v[1000001],v1[1000001];
vector <int> addie[1000001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k,i,j;
cin>>n>>k;
int rez=0;
v[0]=1e9;
for(i=1;i<=n;i++)
{
cin>>v[i];
rez+=(1<<v[i]);
v1[i]=v[i];
while(v[i]>v[steve[vf]])
{
addie[steve[vf]].push_back(v[steve[vf]]);
k--;
rez+=(1<<v[steve[vf]]);
v[steve[vf]]++;
while(vf&&v[steve[vf]]==v[steve[vf-1]])
{
v[steve[vf-1]]++;
vf--;
}
}
while(v[i]==v[steve[vf]])
{
v[i]++;
vf--;
}
steve[++vf]=i;
}
while(v[steve[vf]]!=30)
{
addie[steve[vf]].push_back(v[steve[vf]]);
rez+=(1<<v[steve[vf]]);
k--;
v[steve[vf]]++;
while(vf&&v[steve[vf]]==v[steve[vf-1]])
{
v[steve[vf-1]]++;
vf--;
}
}
assert(rez==(1<<30));
rez=0;
for(i=1;i<=n;i++)
{
cout<<v1[i]<<" ";
rez+=(1<<v1[i]);
for(auto it:addie[i])
{
if(k>=((1<<it)-1))
{
k-=((1<<it)-1);
for(j=1;j<=(1<<it);j++)
cout<<"0 ";
rez+=(1<<it);
continue;
}
else if(k)
{
int a=(int)log2(k)+1;
int newit=it-a;
//daca fac (1<<a) newit-uri, k-=((1<<a)-1)
k=((1<<a)-1)-k;
for(j=1;j<=(1<<a)-2*k;j++)
cout<<newit<<" ";
rez+=(1<<newit)*((1<<a)-2*k);
for(j=1;j<=k;j++)
cout<<newit+1<<" ";
rez+=(1<<(newit+1))*k;
k=0;
}
else
{
cout<<it<<" ";
rez+=(1<<it);
}
}
}
assert(rez==(1<<30));
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |