結果

問題 No.318 学学学学学
ユーザー hirokazu1020hirokazu1020
提出日時 2015-12-11 00:17:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 96,560 KB
実行使用メモリ 11,500 KB
最終ジャッジ日時 2023-09-04 16:20:41
合計ジャッジ時間 4,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,632 KB
testcase_01 AC 23 ms
6,156 KB
testcase_02 AC 27 ms
6,532 KB
testcase_03 AC 19 ms
5,952 KB
testcase_04 AC 24 ms
6,208 KB
testcase_05 AC 149 ms
11,500 KB
testcase_06 AC 125 ms
8,268 KB
testcase_07 AC 110 ms
7,376 KB
testcase_08 AC 95 ms
6,160 KB
testcase_09 AC 83 ms
5,628 KB
testcase_10 AC 66 ms
5,160 KB
testcase_11 AC 151 ms
11,188 KB
testcase_12 AC 106 ms
8,364 KB
testcase_13 AC 91 ms
7,328 KB
testcase_14 AC 76 ms
6,212 KB
testcase_15 AC 66 ms
5,628 KB
testcase_16 AC 55 ms
5,300 KB
testcase_17 AC 87 ms
8,432 KB
testcase_18 AC 80 ms
8,600 KB
testcase_19 AC 91 ms
8,600 KB
testcase_20 AC 38 ms
5,164 KB
testcase_21 AC 3 ms
5,096 KB
testcase_22 AC 3 ms
5,404 KB
testcase_23 AC 3 ms
5,224 KB
testcase_24 AC 3 ms
5,148 KB
testcase_25 AC 3 ms
5,112 KB
testcase_26 AC 3 ms
5,172 KB
testcase_27 AC 3 ms
5,160 KB
testcase_28 AC 3 ms
5,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



class RangeSubstituteTree {//範囲代入
	int n, t;
	std::vector<int> ts, val;
	void substitute(int a, int b, int x, int k, int l, int r) {
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			ts[k] = t;
			val[k] = x;
			return;
		}
		int m = (l + r) / 2;
		substitute(a, b, x, 2 * k + 1, l, m);
		substitute(a, b, x, 2 * k + 2, m, r);
	}
public:
	RangeSubstituteTree(int n = 1 << 20) :n(n) {
		ts.assign(2 * n - 1, t = 0);
		val.assign(2 * n - 1, 0);
	}
	void substitute(int a, int b, int x) {//[a,b)にxを代入
		t++;
		substitute(a, b, x, 0, 0, n);
	}
	int get(int k)const {//k番目の値
		int res, s;
		k += n - 1;
		res = val[k];
		s = ts[k];
		while (k>0) {
			k = (k - 1) / 2;
			if (s<ts[k]) {
				s = ts[k];
				res = val[k];
			}
		}
		return res;
	}
};

int main() {
	map<int, pair<int, int>> idxs;
	int n;
	cin >> n;
	rep(i,n) {
		int a;
		cin >> a;
		if (idxs.find(a) == idxs.end()) {
			idxs[a] = make_pair(i,i);
		}
		else {
			idxs[a].second = i;
		}
	}
	RangeSubstituteTree rst(1<<17);
	for (auto p:idxs) {
		rst.substitute(p.second.first, p.second.second + 1, p.first);
	}
	
	rep(i,n-1) {
		cout << rst.get(i) << ' ';
	}
	cout << rst.get(n - 1) << endl;
}

0