結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー cho435
提出日時 2026-04-18 12:24:34
言語 C++23(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 2,228 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,035 ms
コンパイル使用メモリ 396,332 KB
実行使用メモリ 365,312 KB
最終ジャッジ日時 2026-04-18 12:26:01
合計ジャッジ時間 14,328 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other AC * 2 TLE * 2 -- * 25
権限があれば一括ダウンロードができます

ソースコード

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 ipow(ll x, int a) {
	ll res = 1;
	while (a) {
		if (a & 1) res *= x;
		x *= x;
		a >>= 1;
	}
	return res;
}

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

// template atcoder lazy segtree
struct S {
	ll sm, sz;
	deque<ll> d;
};
S op(S a, S b) {
	a.sm += b.sm;
	a.sz += a.sz;
	if (a.d.size() < b.d.size()) swap(a.d, b.d);
	rep(i, 0, b.d.size()) a.d[i] += b.d[i];
	return a;
}
S e() {
	return {0, 0, {}};
}
struct F {
	int a, c;
	deque<ll> d;
};
S mapping(F f, S x) {
	if (f.c > 0) {
		int ln = min(f.c, (int)x.d.size());
		rep(lp, 0, ln) {
			x.sm -= x.d.front();
			x.d.pop_front();
		}
		return x;
	}
	if (f.a >= 0) {
		x.sm = x.sz * f.a;
		x.d.clear();
		for (int v : f.d) x.d.push_back(x.sz * v);
	}
	return x;
}
F comp(F f, F g) {
	if (f.a >= 0) return f;
	if (f.c > 0) {
		g.c += f.c;
	}
	if (g.a >= 0) {
		int ln = min(g.c, (int)g.d.size());
		rep(lp, 0, ln) {
			g.a -= g.d.front();
			g.d.pop_front();
		}
		g.c = 0;
	}
	return g;
}
F id() {
	return {-1, 0, {}};
}
using segtree = atcoder::lazy_segtree<S, op, e, F, mapping, comp, id>;

deque<ll> build_deq(ll x) {
	deque<ll> res;
	rep(i, 0, 100) {
		ll y = isqrt(x);
		if (x == y) break;
		res.push_back(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((ll)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