結果

問題 No.318 学学学学学
ユーザー しらっ亭しらっ亭
提出日時 2016-09-24 17:40:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 3,175 bytes
コンパイル時間 2,648 ms
コンパイル使用メモリ 177,760 KB
実行使用メモリ 12,524 KB
最終ジャッジ日時 2023-09-04 20:29:36
合計ジャッジ時間 7,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 AC 22 ms
4,944 KB
testcase_02 AC 26 ms
5,376 KB
testcase_03 AC 17 ms
4,472 KB
testcase_04 AC 23 ms
4,904 KB
testcase_05 AC 152 ms
12,524 KB
testcase_06 AC 127 ms
9,356 KB
testcase_07 AC 105 ms
8,312 KB
testcase_08 AC 85 ms
7,564 KB
testcase_09 AC 71 ms
6,848 KB
testcase_10 AC 53 ms
6,288 KB
testcase_11 AC 154 ms
12,288 KB
testcase_12 AC 105 ms
9,456 KB
testcase_13 AC 80 ms
8,188 KB
testcase_14 AC 64 ms
7,608 KB
testcase_15 AC 53 ms
6,860 KB
testcase_16 AC 41 ms
6,208 KB
testcase_17 AC 98 ms
9,452 KB
testcase_18 AC 83 ms
9,480 KB
testcase_19 AC 96 ms
9,500 KB
testcase_20 AC 37 ms
6,108 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;

template <typename V> struct SegTreeLazy {
  static const V zero = 0;
  static const V def = 0;
  struct Node {
    V dat;
    V lazy;
    bool flag;
    Node() : dat(def), lazy(zero), flag(false) {}
  };

  static V merge(const V &l, const V &r) {
    return l + r;
  }

  static V mul(const V &v, const int a) {
    return v * a;
  }

  const int N;
  vector<Node> seg;

  SegTreeLazy(int size) : N(p2(size)), seg(N * 2) {};

  void update(int a, int b, V v) {
    update(a, b, v, 0, 0, N);
  }

  void push(int k, int l, int r) {
    if (seg[k].flag) {
      seg[k].dat = seg[k].lazy;
      if (r - l > 1) {
        seg[k * 2 + 1].lazy = seg[k].lazy;
        seg[k * 2 + 2].lazy = seg[k].lazy;
        seg[k * 2 + 1].flag = true;
        seg[k * 2 + 2].flag = true;
      }
      seg[k].lazy = zero;
      seg[k].flag = false;
    }
  }

  V query(int a, int b) {
    return query(a, b, 0, 0, N);
  }

  private:
  void update(int a, int b, V v, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      seg[k].lazy = v;
      seg[k].flag = true;
      push(k, l, r);
    }
    else {
      update(a, b, v, k * 2 + 1, l, (l + r) / 2);
      update(a, b, v, k * 2 + 2, (l + r) / 2, r);
      seg[k].dat = merge(seg[k * 2 + 1].dat, seg[k * 2 + 2].dat);
    }
  }

  V query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return seg[k].dat;
    V x = query(a, b, k * 2 + 1, l, (l + r) / 2);
    V y = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return merge(x, y);
  }

  static int p2(int n, int m=1) { return m >= n ? m : p2(n, m * 2); }
};

void Main() {
  int N;
  scanf("%d", &N);

  map<int, pii> pos;

  rep(i, N) {
    int a;
    scanf("%d", &a);
    if (pos.count(a)==0) pos[a].fst = pos[a].snd = i;
    else pos[a].snd = i;
  }

  SegTreeLazy<int> seg(N);
  forr(nfl, pos) {
    int f, l;
    tie(f, l) = nfl.snd;
    seg.update(f, l+1, nfl.fst);
    //cout << "seg.seg:"; rep(ii,SZ(seg.seg)) cout << ' ' << seg.seg[ii].lazy; cout << endl;
  }

  rep(i, N) {
    _p("%d ", seg.query(i, i+1));
  }
  _p("\n");
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
0