Submission #926600

#TimeUsernameProblemLanguageResultExecution timeMemory
926600De3b0oStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
262 ms35688 KiB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define er erase
#define pb push_back
#define ppb pop_back()
#define ph push
#define pp pop()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "YES" << "\n";
#define no cout << "NO" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007

using namespace std;

int main()
{
    d3
    ll n;
    cin >> n;
    ll a[n];
    map<ll,set<ll>> mp;
    for(int i = 0 ; n>i ; i++)
    {
        cin >> a[i];
        mp[a[i]].in(i);
    }
    ll ans[n];
    for(int i = 0 ; n>i ; i++)
    {
        auto it = mp[a[i]].upper_bound(i);
        if(it==mp[a[i]].end())
        {
            ans[i]=a[i];
            continue;
        }
        for(int j = i ; *it>j ; j++)
            ans[j]=a[i];
        i=*it-1;
    }
    for(int i = 0 ; n>i ; i++)
        cout << ans[i] << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...