結果

問題 No.318 学学学学学
ユーザー tonetone
提出日時 2019-07-27 05:57:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 81,124 KB
実行使用メモリ 10,788 KB
最終ジャッジ日時 2023-09-15 05:46:27
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 19 ms
4,704 KB
testcase_02 AC 23 ms
4,940 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 20 ms
4,576 KB
testcase_05 AC 138 ms
10,788 KB
testcase_06 AC 151 ms
7,560 KB
testcase_07 AC 141 ms
6,528 KB
testcase_08 AC 126 ms
5,656 KB
testcase_09 AC 116 ms
5,108 KB
testcase_10 AC 100 ms
4,644 KB
testcase_11 AC 143 ms
10,664 KB
testcase_12 AC 124 ms
7,732 KB
testcase_13 AC 110 ms
6,524 KB
testcase_14 AC 94 ms
5,632 KB
testcase_15 AC 82 ms
5,064 KB
testcase_16 AC 69 ms
4,592 KB
testcase_17 AC 104 ms
7,484 KB
testcase_18 AC 81 ms
7,580 KB
testcase_19 AC 111 ms
7,552 KB
testcase_20 AC 52 ms
4,584 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int M=1;
std::vector<int> seg;
void init(int N){
  while(N>M)M*=2;
  M=M*2-1;
  for(int i=0;i<M;i++) seg.push_back(-1);
}
void update(int a, int b, int l, int r, int x, int k){
  if(r<=a||b<=l) return;
  if(a<=l&&r<=b) {
    seg[k]=x;
    return;
  }
  update(a, b, l, (l+r)/2, x, k*2+1);
  update(a, b, (l+r)/2, r, x, k*2+2);
}
int query(int k, int l, int r, int it, int m){
  if((M+1)/2-1<=it&&it<=M) return m;
  if(k<(l+r)/2) return query(k, l, (l+r)/2, it*2+1, max(seg[it],m));
  return query(k, (l+r)/2, r,  it*2+2, max(seg[it],m));
}

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  init(N);
  map<int , pair<int , int> > num;
  std::vector<int> A(N);
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    if(num.find(A[i])==num.end()) num.insert(make_pair(A[i], make_pair(i, -1)));
    else {
      pair<int,int> p = num.at(A[i]);
      num.erase(A[i]);
      num.insert(make_pair(A[i], make_pair(p.first, i)));
    }
  }

  for(int i=0;i<N;i++) seg[i+(M+2)/2-1]=A[i];
  auto itr = num.begin();
  for(int i=0;i<num.size();i++) {
    if((*itr).second.second!=-1) {
      update((*itr).second.first, (*itr).second.second+1, 0, (M+1)/2, (*itr).first, 0);
    }
    itr++;
  }
  for(int i=0;i<N;i++) {
    int ans = query(i, 0, (M+1)/2, 0, -1);
    if(ans <A[i]) ans = A[i];
    std::cout << ans << (i==N-1?"\n":" ");
  }
  return 0;
}
0