結果

問題 No.318 学学学学学
ユーザー tonegawatonegawa
提出日時 2020-08-20 14:21:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 2,689 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 133,700 KB
実行使用メモリ 16,368 KB
最終ジャッジ日時 2024-04-21 10:35:55
合計ジャッジ時間 6,763 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,248 KB
testcase_01 AC 30 ms
5,632 KB
testcase_02 AC 37 ms
6,144 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 32 ms
5,632 KB
testcase_05 AC 226 ms
16,116 KB
testcase_06 AC 222 ms
10,864 KB
testcase_07 AC 187 ms
8,944 KB
testcase_08 AC 166 ms
7,664 KB
testcase_09 AC 149 ms
6,384 KB
testcase_10 AC 121 ms
5,760 KB
testcase_11 AC 215 ms
16,368 KB
testcase_12 AC 165 ms
10,864 KB
testcase_13 AC 146 ms
8,940 KB
testcase_14 AC 129 ms
7,484 KB
testcase_15 AC 111 ms
6,380 KB
testcase_16 AC 96 ms
5,504 KB
testcase_17 AC 147 ms
10,828 KB
testcase_18 AC 121 ms
10,732 KB
testcase_19 AC 158 ms
10,740 KB
testcase_20 AC 76 ms
5,632 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 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