이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define PI acos(-1)
#define LSB(i) ((i) & -(i))
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define MOD 1000000007
#define endl "\n"
#define all(data) data.begin(),data.end()
#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()
#define ima_li_te(D,d) find(all(D),d)
#define MAXN 1000007
ll a[MAXN];
stack<ll> s;
vector<pll> v;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
ll n,k; cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
ll x=a[i];
while(!s.empty() && s.top()<x)
{
ll y=s.top(); v.pb(mp(y,1)); k--;
while(!s.empty() && s.top()==y)
{
s.pop();
y++;
}
s.push(y);
}
v.pb(mp(x,0));
while(!s.empty() && s.top()==x)
{
s.pop();
x++;
}
s.push(x);
}
while(!s.empty() && s.top()<30)
{
ll y=s.top(); v.pb(mp(y,1)); k--;
while(!s.empty() && s.top()==y)
{
s.pop();
y++;
}
s.push(y);
}
for(auto x:v)
{
if(x.sc==1)
{
while(!s.empty()) s.pop();
s.push(x.fi);
while(!s.empty() && k>0)
{
ll y=s.top(); s.pop();
if(y==0) cout<<0<<" ";
else
{
s.push(y-1);
s.push(y-1);
k--;
}
}
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop ();
}
}
else cout<<x.fi<<" ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |