結果

問題 No.318 学学学学学
ユーザー tjaketjake
提出日時 2015-12-13 12:17:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 2,612 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 97,300 KB
実行使用メモリ 14,112 KB
最終ジャッジ日時 2023-09-04 18:08:12
合計ジャッジ時間 6,538 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
8,284 KB
testcase_01 AC 21 ms
8,920 KB
testcase_02 AC 25 ms
9,144 KB
testcase_03 AC 17 ms
8,524 KB
testcase_04 AC 23 ms
8,948 KB
testcase_05 AC 140 ms
14,112 KB
testcase_06 AC 113 ms
11,696 KB
testcase_07 AC 100 ms
10,808 KB
testcase_08 AC 89 ms
10,360 KB
testcase_09 AC 80 ms
9,768 KB
testcase_10 AC 66 ms
9,336 KB
testcase_11 AC 140 ms
14,060 KB
testcase_12 AC 100 ms
11,632 KB
testcase_13 AC 87 ms
10,808 KB
testcase_14 AC 75 ms
10,224 KB
testcase_15 AC 64 ms
9,720 KB
testcase_16 AC 54 ms
9,404 KB
testcase_17 AC 71 ms
11,636 KB
testcase_18 AC 67 ms
11,640 KB
testcase_19 AC 71 ms
11,644 KB
testcase_20 AC 37 ms
9,424 KB
testcase_21 AC 3 ms
7,540 KB
testcase_22 AC 2 ms
7,568 KB
testcase_23 AC 3 ms
7,488 KB
testcase_24 AC 2 ms
7,488 KB
testcase_25 AC 3 ms
7,604 KB
testcase_26 AC 2 ms
7,476 KB
testcase_27 AC 2 ms
7,540 KB
testcase_28 AC 3 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 400003

class StarrySkyTree {
  int n;
  int data[N];
public:
  StarrySkyTree(int n_) {
    n = 1;
    while(n < n_) n *= 2;
    rep(i, 2*n) data[i] = 0;
  }

  void update(int k, int a) {
    k += n-1;
    data[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = maxd(data[2*k+1], data[2*k+2]);
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if(b<=l || r<=a) return 0;
    if(l<=a && b<=r) return data[k];

    int vl = query(a, b, 2*k+1, l, (l + r) / 2);
    int vr = query(a, b, 2*k+2, (l + r) / 2, r);

    return maxd(vl, vr);
  }

  int get_max(int a, int b) {
    return query(a, b, 0, 0, n);
  }
};

int n;
int a[N], b[N];
int le[N], ri[N];

int main() {
  map<int, int> m;
  cin >> n;
  int idx = 0;
  rep(i, n) {
    cin >> a[i];
    if(!m.count(a[i])) {
      m[a[i]] = idx++;
    }
  }
  rep(i, n) le[i] = ri[i] = -1;
  rep(i, n) {
    b[i] = m[a[i]];
  }

  rep(i, n) {
    if(le[b[i]]==-1) {
      le[b[i]] = i;
    }
  }
  repr(i, n) {
    if(ri[b[i]]==-1) {
      ri[b[i]] = i;
    }
  }

  StarrySkyTree sst(n);
  rep(i, n) {
    if(le[b[i]] == i) {
      sst.update(b[i], a[i]);
    }
    cout << (i ? " " : "") << sst.get_max(0, n);
    if(ri[b[i]] == i) {
      sst.update(b[i], 0);
    }
  }
  cout << endl;

  return 0;
}
0