結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー cho435
提出日時 2026-04-18 14:19:51
言語 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
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 2,239 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,732 ms
コンパイル使用メモリ 382,060 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2026-04-18 14:20:07
合計ジャッジ時間 14,353 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

using mint = atcoder::modint998244353;

ll isqrt(ll n) {
	if (n <= 0) return 0;
	ll x = sqrt(n);
	if (x * x > n) x--;
	return x;
}

constexpr int ar = 6;

// template atcoder lazy segtree
struct S {
	ll sm, sz;
	array<ll, ar> d;
};
S op(S a, S b) {
	a.sm += b.sm;
	a.sz += a.sz;
	rep(i, 0, ar) a.d[i] += b.d[i];
	return a;
}
S e() {
	return {0, 0, array<ll, ar>{}};
}
struct F {
	ll a, c;
	array<ll, ar> d;
};
S mapping(F f, S x) {
	if (f.c > 0) {
		int ln = min((ll)ar, f.c);
		rep(i, 0, ln) {
			x.sm -= x.d[i];
			x.d[i] = 0;
		}
		rep(i, ln, ar) {
			x.d[i - ln] = x.d[i];
			x.d[i] = 0;
		}
		return x;
	}
	if (f.a >= 0) {
		x.sm = x.sz * f.a;
		rep(i, 0, ar) x.d[i] = f.d[i] * x.sz;
	}
	return x;
}
F comp(F f, F g) {
	assert((f.a < 0) || (f.c == 0));
	assert((g.a < 0) || (g.c == 0));
	if (f.a >= 0) return f;
	if (f.c > 0) {
		g.c += f.c;
	}
	if (g.a >= 0 && g.c > 0) {
		int ln = min((ll)ar, g.c);
		rep(i, 0, ln) {
			g.a -= g.d[i];
			g.d[i] = 0;
		}
		rep(i, ln, ar) {
			g.d[i - ln] = g.d[i];
			g.d[i] = 0;
		}
		g.c = 0;
	}
	return g;
}
F id() {
	return {-1, 0, array<ll, ar>{}};
}
using segtree = atcoder::lazy_segtree<S, op, e, F, mapping, comp, id>;

array<ll, ar> build_deq(ll x) {
	array<ll, ar> res;
	rep(i, 0, ar) {
		ll y = isqrt(x);
		res[i] = x - y;
		x = y;
	}
	return res;
}

void solve() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	segtree seg;
	{
		vector<S> tmp(n);
		rep(i, 0, n) tmp[i] = S{a[i], 1, build_deq(a[i])};
		seg = segtree{tmp};
	}
	while (q--) {
		int t, l, r;
		cin >> t >> l >> r;
		if (t == 0) cout << seg.prod(l, r).sm << '\n';
		if (t == 1) {
			int x;
			cin >> x;
			seg.apply(l, r, F{x, 0, build_deq(x)});
		}
		if (t == 2) seg.apply(l, r, F{-1, 1, {}});
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	int t = 1;
	// cin >> t;
	while (t--) solve();
}
0