結果

問題 No.318 学学学学学
ユーザー peroon
提出日時 2019-04-18 08:17:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 182,328 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-06-22 18:49:49
合計ジャッジ時間 4,434 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // その値が出てくる最後の位置
    map<ll, ll> mp;
    FOR(i, 0, N){
        mp[A[i]] = i;
    }

    set<ll> se;
    FOR(i, 0, N-1){
        ll a = A[i];
        se.insert(a);

        ll ma = *se.rbegin();
        A[i] = ma;

        if(mp[a]==i){
            se.erase(a);
        }
    }

    cout << A[0];
    FOR(i, 1, N){
        cout << " " << A[i];
    }
    cout << endl;
    
    return 0;
}
0