結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー apricity
提出日時 2026-04-19 14:05:29
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,626 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,818 ms
コンパイル使用メモリ 216,460 KB
実行使用メモリ 13,968 KB
最終ジャッジ日時 2026-04-19 15:21:32
合計ジャッジ時間 11,001 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// https://atcoder.jp/contests/abc256/submissions/32369947
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#include "atcoder/lazysegtree.hpp"

using ll = long long;
using pl = pair<ll, ll>;
pl ti() { return {0, 0}; }
ll ei() { return -1; }
pl f(pl a, pl b) { return pl{a.first + b.first, a.second + b.second}; }
pl g(ll b, pl a) { return b == ei() ? a : pl{a.second * b, a.second}; }
ll h(ll b, ll a) { return b == ei() ? a : b; }
using segtree = atcoder::lazy_segtree<pl, f, ti, ll, g, h, ei>;

struct interval_manager {
  using T = int;
  map<T, T> st;
  interval_manager() = default;

  using const_iterator = typename map<T, T>::const_iterator;
  const_iterator begin() const { return st.begin(); }
  const_iterator end() const { return st.end(); }
  const_iterator lower_bound(T x) const {
    auto it = st.lower_bound(x);
    if (it == st.begin() || prev(it)->second <= x) return it;
    return prev(it);
  }
  const_iterator erase(const_iterator it) { return st.erase(it); }

  void erase(T l, T r) {
    auto L = st.upper_bound(l), R = st.upper_bound(r);
    if (L != st.begin() && l <= prev(L)->second) --L;
    if (L == R) return;
    T nl = min(l, L->first), nr = max(r, prev(R)->second);
    st.erase(L, R);
    if (nl < l) st[nl] = l;
    if (r < nr) st[r] = nr;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<ll> a(N);
  for (auto& x : a) cin >> x;

  segtree seg(N);
  interval_manager m;

  // i に切れ目を入れる
  auto cut = [&](int i) {
    auto it = m.lower_bound(i);
    if (it == end(m)) return;
    auto [x, y] = *it;
    if (x < i and i < y) {
      m.erase(it);
      m.st[x] = i;
      m.st[i] = y;
    }
  };

  for (int i = 0; i < N; i++) {
    seg.set(i, {a[i], 1});
    m.st[i] = i + 1;
  }
  for (int i = 0; i < Q; i++) {
    int cmd, L, R, x = -1;
    cin >> cmd >> L >> R;
    // --L;
    if (cmd == 2) {
      // cin >> x;
      cut(L), cut(R);
      for (auto it = m.lower_bound(L); it != end(m);) {
        auto [l, r] = *it;
        if (R <= l) break;
        assert(L <= l and r <= R);
        int n = seg.get(l).first;
        n = sqrtl(n);
        seg.apply(l, r, n);
        if (n <= 1) {
          it = m.erase(it);
        } else {
          it++;
        }
      }
    } else if (cmd == 1) {
      cin >> x;
      m.erase(L, R);
      m.st[L] = R;
      seg.apply(L, R, x);
    } else {
      cout << seg.prod(L, R).first << "\n";
    }
    
    //for (int j = 0; j < N; j++) cerr << seg.get(j).first << ",";
    //cerr << "sum:" << seg.prod(0, N).first << endl;
  }
}
0