結果
問題 |
No.1526 Sum of Mex 2
|
ユーザー |
![]() |
提出日時 | 2021-06-03 00:54:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,442 bytes |
コンパイル時間 | 2,972 ms |
コンパイル使用メモリ | 117,452 KB |
最終ジャッジ日時 | 2025-01-21 21:10:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'S op(S, S)': main.cpp:12:96: error: could not convert '{(l.S::sum + r.S::sum), ((l.S::max > r.S::max) ? l.S::max : r.S::max), (l.S::size + r.S::size)}' from '<brace-enclosed initializer list>' to 'S' 12 | S op(S l, S r) noexcept { return {l.sum + r.sum, l.max > r.max ? l.max : r.max, l.size + r.size}; } | ^ | | | <brace-enclosed initializer list> main.cpp: In function 'S e()': main.cpp:13:33: error: could not convert '{0, 0, 0}' from '<brace-enclosed initializer list>' to 'S' 13 | S e() noexcept { return {0, 0, 0}; } | ^ | | | <brace-enclosed initializer list> main.cpp: In function 'S mapping(unsigned int, S)': main.cpp:14:106: error: no matching function for call to 'S::S(<brace-enclosed initializer list>)' 14 | S mapping(unsigned f, S x) noexcept { return f ? S{(unsigned long long)x.size * f, x.size ? f : 0, x.size} : x; } | ^ main.cpp:10:5: note: candidate: 'constexpr S::S()' 10 | S() = default; | ^ main.cpp:10:5: note: candidate expects 0 arguments, 3 provided main.cpp:7:8: note: candidate: 'constexpr S::S(const S&)' 7 | struct S { | ^ main.cpp:7:8: note: candidate expects 1 argument, 3 provided main.cpp:7:8: note: candidate: 'constexpr S::S(S&&)' main.cpp:7:8: note: candidate expects 1 argument, 3 provided main.cpp: In function 'int main()': main.cpp:31:71: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<S>, S>::value_type' {ak
ソースコード
#include <iostream> #include <vector> using namespace std; #include <atcoder/lazysegtree> using ull = unsigned long long; struct S { ull sum; unsigned max, size; S() = default; }; S op(S l, S r) noexcept { return {l.sum + r.sum, l.max > r.max ? l.max : r.max, l.size + r.size}; } S e() noexcept { return {0, 0, 0}; } S mapping(unsigned f, S x) noexcept { return f ? S{(unsigned long long)x.size * f, x.size ? f : 0, x.size} : x; } unsigned composition(unsigned f, unsigned g) noexcept { return f ? f : g; } unsigned id() noexcept { return 0; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); unsigned N; cin >> N; vector<vector<unsigned>> v2is(N); for (unsigned i = 0; i < N; i++) { unsigned a; cin >> a; v2is[a - 1].push_back(i); } long long ret = 0; vector<S> init(N); for (int i = 0; i < N; i++) init[i] = {(unsigned)i, (unsigned)i, 1}; atcoder::lazy_segtree<S, op, e, unsigned, mapping, composition, id> tree(init); for (int h = 0; h < N; h++) { int l = 0; for (auto i : v2is[h]) { int r = tree.max_right(l, [&](S x) { return x.max <= i; }); if (l < r) tree.apply(l, r, i); l = i + 1; } tree.apply(l, N, N); auto tmp = (long long)N * N - tree.all_prod().sum; ret += tmp; if (!tmp) break; } cout << ret + (long long)N * (N + 1) / 2 << '\n'; }