Submission #925585

#TimeUsernameProblemLanguageResultExecution timeMemory
925585vjudge1Stone Arranging 2 (JOI23_ho_t1)C++17
60 / 100
372 ms27732 KiB
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <tuple>
#include <math.h>
#include <string>
#include <map>
#include <vector>
#include <iterator>
#include <queue>//pq.push(追加),取り出し=pq.top(),pq.pop()削除。
#include <functional> // std::greater
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define in(...) cin >> __VA_ARGS__
#define out(...) cout << __VA_ARGS__ << endl
typedef long long int ll; 

// index が条件を満たすかどうか
bool isOK(long long index, long long key, const vector<long long>& b) {
    if (b[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(long long key, const vector<long long>& b) {
    ll left = -1;//「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = b.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key, b)) right = mid;
        else left = mid;
    }
     /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */

    return left;
}
//vector同氏の比較
struct Compare {
    bool operator()(const vector<ll>& a, const vector<ll>& b) const {
        // aとbの比較ロジックを記述
        // 例: a[0] が小さい場合、a を優先
        return a[0] > b[0];
    }
};

int main() {
    ll n,x,akey;
    vector<vector<ll>> a;
    map<ll,ll> irotoban;
    akey=0;
    in(n);
    a.resize(n, std::vector<ll>(2, 0));
    rep(i,n){
        if (i==0){
            in(a[akey][0]);
            irotoban[a[akey][0]]=akey;
            continue;
        }
        in(x);
        if (a[akey][0]==x){
            a[akey][1]=i;
        }
        else{
            if (irotoban.find(x)==irotoban.end()){
                akey+=1;
                a[akey][0]=x;
                a[akey][1]=i;
                irotoban[x]=akey;
            }
            else if(irotoban[x]<akey){
                akey=irotoban[x];
                a[akey][1]=i;

            }
            else{
                akey+=1;
                a[akey][0]=x;
                a[akey][1]=i;
                irotoban[x]=akey;

            }

        }
        
        
    }
    rep(i,akey+1){
        if (i==0){
            rep(k,a[i][1]+1){
                out(a[i][0]);
            }
        }
        else{
        rep(k,a[i][1]-a[i-1][1]){
            out(a[i][0]);
        }
        }
    }


}

   
    

//2213
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...