結果
問題 |
No.318 学学学学学
|
ユーザー |
|
提出日時 | 2016-09-01 23:44:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 1,908 bytes |
コンパイル時間 | 1,108 ms |
コンパイル使用メモリ | 96,340 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-22 17:54:39 |
合計ジャッジ時間 | 4,550 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#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; }