結果

問題 No.318 学学学学学
ユーザー 👑 CleyL
提出日時 2021-12-11 14:37:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 88,280 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-07-19 19:38:55
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;
int main(){
  int n;cin>>n;
  map<int,pair<int,int>> A;
  for(int i = 0; n > i; i++){
    int t;cin>>t;
    if(!A[t].first){
      A[t].first = i+1;
    }
    A[t].second = i+1;
  }
  vector<int> ret[n+1],ans(n);
  for(auto x: A){
    ret[x.second.first-1].push_back(x.first);
    ret[x.second.second].push_back(-x.first);
  }

  priority_queue<int> C;
  priority_queue<int> eraser;

  for(int i = 0; n > i; i++){
    for(int j = 0; ret[i].size() > j; j++){
      if(ret[i][j]>0){
        C.push(ret[i][j]);
      }else if(ret[i][j] < 0){
        eraser.push(-1*ret[i][j]);
      }
    }
    while(C.size() && eraser.size() && C.top() == eraser.top()){
      C.pop();
      eraser.pop();
    }
    ans[i] = C.top();
  }
  for(int i = 0; n > i; i++){
    cout << ans[i];
    if(i+1 != n)cout << " ";
  }
  cout << endl;
  

}
0