結果

問題 No.318 学学学学学
ユーザー kurenaifkurenaif
提出日時 2018-09-15 05:26:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 7,481 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 124,300 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-06-22 18:43:04
合計ジャッジ時間 5,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 24 ms
6,940 KB
testcase_02 AC 27 ms
6,940 KB
testcase_03 AC 17 ms
6,940 KB
testcase_04 AC 25 ms
6,944 KB
testcase_05 AC 182 ms
13,568 KB
testcase_06 AC 156 ms
10,496 KB
testcase_07 AC 125 ms
9,472 KB
testcase_08 AC 108 ms
8,576 KB
testcase_09 AC 85 ms
8,064 KB
testcase_10 AC 61 ms
7,424 KB
testcase_11 AC 164 ms
13,568 KB
testcase_12 AC 115 ms
10,496 KB
testcase_13 AC 95 ms
9,600 KB
testcase_14 AC 74 ms
8,576 KB
testcase_15 AC 63 ms
8,064 KB
testcase_16 AC 49 ms
7,424 KB
testcase_17 AC 120 ms
10,496 KB
testcase_18 AC 96 ms
10,624 KB
testcase_19 AC 122 ms
10,496 KB
testcase_20 AC 48 ms
7,552 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,948 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <type_traits>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define inf 0x3f3f3f3f3f3f3f3f
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
using pii = pair<ll, ll>;
#define eps 1e-14
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15) << std::fixed;

template <class T>
using vec2 = std::vector<vector<T>>;

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template < typename T >
struct is_vector : std::false_type {};

template < typename T >
struct is_vector<std::vector<T>> : std::true_type {};

template < typename T >
constexpr bool is_vector_v = is_vector<T>::value;

template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
	if (!v.empty()) {
		for (int i = 0; i < v.size(); ++i) {
			out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", "));
		}
	}
	return out;
}

namespace std {
	// ref: https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
	template <class T>
	inline void hash_combine(std::size_t& seed, T const& v)
	{
		seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
	}

	// Recursive template code derived from Matthieu M.
	template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
	struct HashValueImpl
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
			hash_combine(seed, std::get<Index>(tuple));
		}
	};

	template <class Tuple>
	struct HashValueImpl<Tuple, 0>
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			hash_combine(seed, std::get<0>(tuple));
		}
	};
	template <typename ... TT>
	struct hash<std::tuple<TT...>>
	{
		size_t operator()(std::tuple<TT...> const& tt) const
		{
			size_t seed = 0;
			HashValueImpl<std::tuple<TT...> >::apply(seed, tt);
			return seed;
		}
	};

	template <class T, class U>
	class hash<std::pair<T, U>> {
	public:
		size_t operator()(const std::pair<T, U>& x) const {
			return hash<std::tuple<T, U>>()(std::tie(x.first, x.second));
		}
	};
}

// ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple
namespace aux {
	template<std::size_t...> struct seq {};

	template<std::size_t N, std::size_t... Is>
	struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};

	template<std::size_t... Is>
	struct gen_seq<0, Is...> : seq<Is...> {};

	template<class Ch, class Tr, class Tuple, std::size_t... Is>
	void print_tuple(std::basic_ostream<Ch, Tr>& os, Tuple const& t, seq<Is...>) {
		using swallow = int[];
		(void)swallow {
			0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...
		};
	}
} // aux::

template<class Ch, class Tr, class... Args>
auto operator<<(std::basic_ostream<Ch, Tr>& os, std::tuple<Args...> const& t)
-> std::basic_ostream<Ch, Tr>&
{
	os << "(";
	aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>());
	return os << ")";
}

template<class S, class T>
std::ostream & operator<<(std::ostream & os, const std::pair<S, T> & p)
{
	return os << "(" << p.first << ", " << p.second << ")";
}

// ref: https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp
template <typename T>
struct reversion_wrapper { T& iterable; };

template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }

template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }

template <typename T>
reversion_wrapper<T> REV(T&& iterable) { return { iterable }; }

template<class T>
bool inside(T left, T val, T right) {
	return left <= val and val < right;
}

int bitCount(int num) {
	int res = 0;
	while (num > 0) {
		num >>= 1;
		++res;
	}
	return res;
}

ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUGa
	//system("pause");
#endif
	return 0;
}

// template

#define int long long

template<class T>
class LazySegtree {
private:
	int n;
	vector<T> dat;
	vector<T> lazy;
	vector<bool> lazyFlag;

	void eval(int k, int l, int r){
		if (lazyFlag[k]) {
			dat[k] = lazy[k];

			if (r - l > 1) {
				lazy[2 * k + 1] = lazy[k];
				lazy[2 * k + 2] = lazy[k];
				lazyFlag[2 * k + 1] = lazyFlag[2 * k + 2] = true;
			}
		}

		lazyFlag[k] = false;
	}

	T query(int a, int b, int k, int l, int r) {
		eval(k, l, r);
		if (r <= a || b <= l) return numeric_limits<T>::max();

		if (a <= l & r <= b) return dat[k];

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

		return min(vl, vr);
	}

	// change [a,b) to value
	void update(int a, int b, T value, int k, int l, int r){
		eval(k, l, r);
		if (b <= l or r <= a) return;

		if (a <= l and r <= b) {
			lazy[k] = value;
			lazyFlag[k] = true;
			eval(k, l, r);
		}
		else {
			update(a, b, value, 2 * k + 1, l, (l + r) / 2);
			update(a, b, value, 2 * k + 2, (l + r) / 2, r);
			dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
public:
	LazySegtree(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.resize(2 * n - 1);
		lazy.resize(2 * n - 1);
		lazyFlag.resize(2 * n - 1);
		for (int i = 0; i < 2 * n - 1; ++i) dat[i] = numeric_limits<T>::max();
	}


	// change [a,b] to value
	void update(int a, int b, T value){
		update(a, b, value, 0, 0, n);
	}

	// change k to value
	void update(int k, T value) {
		update(k, k + 1, value);
	}

	// get min value at [a, b)
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

void solve() {
	int N; cin >> N;
	map<int, pair<int, int>> field;
	LazySegtree<int> seg(N);
	REP(i, N) {
		int a; cin >> a;
		auto it = field.find(a);
		if (it == field.end()) field[a] = {i, i};
		field[a].second = i;
	}

	for (auto &a : field) {
		seg.update(a.second.first, a.second.second + 1, -(a.first));
	}

	REP(i, N) {
		cout << -seg.query(i, i + 1) << " ";
	}
}
0