Submission #1144677

#TimeUsernameProblemLanguageResultExecution timeMemory
114467712345678Zalmoxis (BOI18_zalmoxis)C++20
35 / 100
118 ms32324 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e6+5;

int n, k, a[nx], cnt;
stack<pair<int, int>> s;
vector<int> res[nx];

void insert(pair<int, int> x)
{
    if (s.empty()) s.push(x);
    else
    {
        if (s.top().first==x.first) s.pop(), insert({x.first+1, x.second});
        else s.push(x);
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++)
    {
        if (s.empty()) s.push({a[i], i});
        else
        {
            while (s.top().first<a[i])
            {
                auto [x, y]=s.top();
                s.pop();
                res[y].push_back(x);
                cnt++;
                insert({x+1, y});
            }
            insert({a[i], i});
        }
    }
    while (s.top().first<30)
    {
        auto [x, y]=s.top();
        s.pop();
        res[y].push_back(x);
        cnt++;
        insert({x+1, y});
    }
    for (int i=1; i<=n; i++)
    {
        cout<<a[i]<<' ';
        for (auto x:res[i]) cout<<x<<' ';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...