結果

問題 No.3367 Looks like a convolution
コンテスト
ユーザー risujiroh
提出日時 2025-11-17 23:30:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,501 ms / 2,000 ms
コード長 2,667 bytes
コンパイル時間 3,030 ms
コンパイル使用メモリ 292,816 KB
実行使用メモリ 31,644 KB
最終ジャッジ日時 2025-11-17 23:30:58
合計ジャッジ時間 23,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

void Solve() {
  int n;
  IN(n);
  vector<int64_t> a(n);
  IN(a);
  vector<int64_t> b(n);
  IN(b);

  vector<int64_t> c(n);

  struct S {
    int64_t sum;
    int64_t len;
  };

  atcoder::lazy_segtree<
      S,
      [](const S& x, const S& y) { return S(x.sum + y.sum, x.len + y.len); },
      [] { return S(0, 0); },
      int64_t,
      [](int64_t f, S x) {
        if (f != -1) {
          x.sum = x.len * f;
        }
        return x;
      },
      [](int64_t g, int64_t f) { return g == -1 ? f : g; },
      [] { return INT64_C(-1); }>
      seg_a(n), seg_b(n);

  for (int k : Rep(0, n)) {
    seg_a.set(k, {a[k], 1});
    seg_b.set(k, {b[k], 1});

    {
      int ok = -1;
      int ng = k;
      while (ok + 1 < ng) {
        int mid = midpoint(ok, ng);
        (seg_a.get(mid).sum <= a[k] ? ok : ng) = mid;
      }
      seg_a.apply(ng, k, a[k]);
    }
    {
      int ok = -1;
      int ng = k;
      while (ok + 1 < ng) {
        int mid = midpoint(ok, ng);
        (seg_b.get(mid).sum <= b[k] ? ok : ng) = mid;
      }
      seg_b.apply(ng, k, b[k]);
    }

    int ng = -1;
    int ok = k + 1;
    while (ng + 1 < ok) {
      int mid = midpoint(ng, ok);
      (seg_a.get(mid).sum < seg_b.get(k - mid).sum ? ng : ok) = mid;
    }
    c[k] += seg_a.prod(0, ok).sum + seg_b.prod(0, k - ok + 1).sum;
    // for (int i : Rep1(0, k)) {
    //   c[k] += min(seg_a.get(i).sum, seg_b.get(k - i).sum);
    // }
  }

  OUT(c);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  Solve();
}

#elif __INCLUDE_LEVEL__ == 1

#include <bits/stdc++.h>

#include <atcoder/lazysegtree.hpp>

template <class T> concept MyRange = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;

namespace std {

istream& operator>>(istream& is, MyRange auto&& r) {
  for (auto&& e : r) is >> e;
  return is;
}
istream& operator>>(istream& is, MyTuple auto&& t) {
  apply([&](auto&... xs) { (is >> ... >> xs); }, t);
  return is;
}

ostream& operator<<(ostream& os, MyRange auto&& r) {
  auto sep = "";
  for (auto&& e : r) os << exchange(sep, " ") << e;
  return os;
}
ostream& operator<<(ostream& os, MyTuple auto&& t) {
  auto sep = "";
  apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
  return os;
}

}  // namespace std

using namespace std;

#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')

#endif  // __INCLUDE_LEVEL__ == 1
0