結果

問題 No.318 学学学学学
ユーザー tonetone
提出日時 2019-12-01 05:06:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 2,689 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 113,116 KB
実行使用メモリ 16,368 KB
最終ジャッジ日時 2024-05-01 03:42:15
合計ジャッジ時間 7,116 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,812 KB
testcase_01 AC 34 ms
6,940 KB
testcase_02 AC 41 ms
6,940 KB
testcase_03 AC 25 ms
6,940 KB
testcase_04 AC 33 ms
6,944 KB
testcase_05 AC 262 ms
16,368 KB
testcase_06 AC 249 ms
10,740 KB
testcase_07 AC 208 ms
8,944 KB
testcase_08 AC 181 ms
7,536 KB
testcase_09 AC 156 ms
6,944 KB
testcase_10 AC 123 ms
6,944 KB
testcase_11 AC 244 ms
16,240 KB
testcase_12 AC 183 ms
10,864 KB
testcase_13 AC 156 ms
9,072 KB
testcase_14 AC 132 ms
7,660 KB
testcase_15 AC 118 ms
6,940 KB
testcase_16 AC 97 ms
6,940 KB
testcase_17 AC 155 ms
10,868 KB
testcase_18 AC 128 ms
10,864 KB
testcase_19 AC 165 ms
10,800 KB
testcase_20 AC 79 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int INF = 1000000000;
struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};
int main(int argc, char const *argv[]) {
  ll n, a;std::cin >> n;
  map<ll, vll> mp;
  LazySegmentTree seg( vector<int>(n, INF) );
  for(int i=0;i<n;i++){
    std::cin >> a;
    if(mp.find(a)==mp.end()) mp.emplace(a, vll{i, i});
    else{
      vll p = mp.at(a);
      p[0] = min(p[0], (ll)i), p[1] = max(p[1], (ll)i);
      mp.erase(a);
      mp.emplace(a, p);
    }
  }
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    //std::cout << (*itr).first << " " <<  (*itr).second[0] << " " << (*itr).second[1] << '\n';
    seg.update((*itr).second[0], (*itr).second[1]+1, (*itr).first);
  }
  for(int i=0;i<n;i++){
    std::cout << seg.find(i, i+1) << (i==n-1?"\n":" ");
  }
  return 0;
}
0