Submission #1281264

#TimeUsernameProblemLanguageResultExecution timeMemory
1281264tunademayoStone Arranging 2 (JOI23_ho_t1)C++20
0 / 100
1 ms568 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second

const bool Multitest = 0;

const int N = 2e5 + 10;

int cnt[N]; stack<pair<int, int>> t;
int a[N], n;

void work()
{
    cin >> n;

    for(int i = 1 ; i <= n ; i++)
    {
        cin >> a[i];
    }

    for(int i = 1 ; i <= n ; i++)
    {
        cerr << i << '\n';

        if(cnt[a[i]] == 0)
        {
            // do nothing here
        }
        else
        {
            while(true)
            {
                pair<int, int> x = t.top(); t.pop();

                if(x.fi == a[i])
                {
                    break;
                }
                else
                {
                    cnt[x.fi] = 0;
                }
            }
        }

        cnt[a[i]]++;
        t.push({a[i], cnt[a[i]]});
    }

    int last = n;

    while(!t.empty())
    {
        pair<int, int> x = t.top(); t.pop();

        int tmp = last;
        last -= x.se;

        for(int i = last + 1 ; i <= tmp ; i++) a[i] = x.fi;
    }

    for(int i = 1 ; i <= n ; i++) cout << a[i] << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    if(fopen("task.inp", "r"))
    {
        freopen("task.inp", "r", stdin);
        freopen("task.out", "w", stdout);
    }

    int q = 1;

    if(Multitest)   cin >> q;

    while(q--) work();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...