結果
問題 | No.318 学学学学学 |
ユーザー | kimiyuki |
提出日時 | 2016-09-01 23:44:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,908 bytes |
コンパイル時間 | 1,130 ms |
コンパイル使用メモリ | 94,380 KB |
実行使用メモリ | 11,232 KB |
最終ジャッジ日時 | 2023-09-04 20:20:20 |
合計ジャッジ時間 | 5,141 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
4,380 KB |
testcase_01 | AC | 24 ms
4,784 KB |
testcase_02 | AC | 29 ms
5,000 KB |
testcase_03 | AC | 19 ms
4,684 KB |
testcase_04 | AC | 25 ms
5,032 KB |
testcase_05 | AC | 165 ms
11,232 KB |
testcase_06 | AC | 136 ms
7,852 KB |
testcase_07 | AC | 118 ms
6,872 KB |
testcase_08 | AC | 101 ms
6,168 KB |
testcase_09 | AC | 89 ms
5,436 KB |
testcase_10 | AC | 72 ms
5,020 KB |
testcase_11 | AC | 163 ms
11,024 KB |
testcase_12 | AC | 115 ms
7,920 KB |
testcase_13 | AC | 99 ms
6,804 KB |
testcase_14 | AC | 84 ms
6,004 KB |
testcase_15 | AC | 71 ms
5,552 KB |
testcase_16 | AC | 55 ms
4,972 KB |
testcase_17 | AC | 103 ms
7,856 KB |
testcase_18 | AC | 89 ms
7,852 KB |
testcase_19 | AC | 102 ms
7,924 KB |
testcase_20 | AC | 39 ms
5,112 KB |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 1 ms
4,380 KB |
testcase_25 | AC | 1 ms
4,384 KB |
testcase_26 | AC | 2 ms
4,380 KB |
testcase_27 | AC | 2 ms
4,376 KB |
testcase_28 | AC | 1 ms
4,380 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <cmath> #include <functional> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; } template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; } template <typename T> struct co_segment_tree { // on monoid int n; vector<T> a; function<T (T,T)> append; // associative, symmetric co_segment_tree() = default; template <typename F> co_segment_tree(int a_n, T a_init, F a_append) { n = pow(2,ceil(log2(a_n))); a.resize(2*n-1, a_init); append = a_append; } void range_update(int l, int r, T z) { range_update(0, 0, n, l, r, z); } void range_update(int i, int il, int ir, int l, int r, T z) { if (l <= il and ir <= r) { a[i] = append(a[i], z); } else if (ir <= l or r <= il) { // nop } else { range_update(2*i+1, il, (il+ir)/2, l, r, z); range_update(2*i+2, (il+ir)/2, ir, l, r, z); } } T point_concat(int i) { T z = a[i+n-1]; for (i = (i+n)/2; i > 0; i /= 2) { z = append(z, a[i-1]); } return z; } }; int main() { // input int n; cin >> n; vector<int> as(n); repeat (i,n) cin >> as[i]; // compute map<int,pair<int,int> > q; repeat (i,n) { if (not q.count(as[i])) q[as[i]] = { i, i }; setmin(q[as[i]].first, i); setmax(q[as[i]].second, i); } co_segment_tree<int> t(n, 0, [](int a, int b) { return max(a, b); }); for (auto it : q) { int a = it.first; int l, r; tie(l, r) = it.second; t.range_update(l, r+1, a); } // output repeat (i,n) { if (i) cout << ' '; cout << t.point_concat(i); } cout << endl; return 0; }