結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー ponjuice
提出日時 2026-04-18 18:12:41
言語 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  
実行時間 611 ms / 2,000 ms
コード長 4,765 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,761 ms
コンパイル使用メモリ 344,336 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2026-04-18 18:13:05
合計ジャッジ時間 22,717 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

//高速化 
struct ponjuice{ponjuice(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}}PonJuice;
//#define endl '\n' //インタラクティブ問題の時は消す

//型
using ll = long long;
using ld = long double;
template<class T>using vc = vector<T>; template<class T>using vvc = vc<vc<T>>; template<class T>using vvvc = vvc<vc<T>>;
using vi = vc<int>;  using vvi = vvc<int>;  using vvvi = vvvc<int>;
using vl = vc<ll>;   using vvl = vvc<ll>;   using vvvl = vvvc<ll>;
using pi = pair<int, int>;  using pl = pair<ll, ll>;
using ull = unsigned ll;
template<class T>using priq = priority_queue<T>;
template<class T>using priqg = priority_queue<T, vc<T>, greater<T>>;

// for文
#define overload4(a, b, c, d, e, ...) e
#define rep1(n)             for(ll i = 0; i < n; i++)
#define rep2(i, n)          for(ll i = 0; i < n; i++)
#define rep3(i, a, b)       for(ll i = a; i < b; i++)
#define rep4(i, a, b, step) for(ll i = a; i < b; i+= step)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define per1(n)             for(ll i = n-1; i >= 0; i--)
#define per2(i, n)          for(ll i = n-1; i >= 0; i--)
#define per3(i, a, b)       for(ll i = b-1; i >= a; i--)
#define per4(i, a, b, step) for(ll i = b-1; i >= a; i-= step)
#define per(...) overload4(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)

//関数
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define si(x) (ll)(x).size()
template<class S, class T>inline bool chmax(S& a, T b){return a < b && ( a = b , true);}
template<class S, class T>inline bool chmin(S& a, T b){return a > b && ( a = b , true);}

inline void yes(){cout << "Yes\n";}
inline void no(){cout << "No\n";}
inline void yesno(bool y = true){if(y)yes();else no();}

//定数
constexpr ll mod = 998244353;
constexpr ll minf=-(1<<29);
constexpr ll inf=(1<<29);
constexpr ll MINF=-(1LL<<60);
constexpr ll INF=(1LL<<60);
const int dx[4] ={-1, 0, 1, 0};
const int dy[4] ={ 0, 1, 0,-1};
const int dx8[8] ={-1,-1,-1, 0, 1, 1, 1, 0};
const int dy8[8] ={-1, 0, 1, 1, 1, 0,-1,-1};

void solve();
int main() {
	int t = 1;
    // cin >>t;
    while(t--){
        solve();
    }
}

/*
せっかくなので、PPC は全てコメント書きます


遅延セグ木に無理やりのせたいね
↑できそう

sqrtで減る操作になるのは高々6回程度なので、減る量を持ってあげればいい
*/


ll sqrtll(ll x) {
    ll res = sqrtl(x);
    while(res*res < x) res++;
    while(res*res > x) res--;
    return res;
}

#include<atcoder/lazysegtree>
using namespace atcoder;
using S = array<ll,9>; // sum と len とsq での減る量
S op(S a, S b) {
    S res;
    rep(i,0,9) res[i] = a[i] + b[i];
    return res;
}
S e() {
    return {0,0,0,0,0,0,0,0,0};
}
using F = array<ll,9>; // それぞれの値の減る量
S mapping(F a, S b) {
    if(a[0] == -1) {
        // sqrtの適用のみ
        ll k = a[1];
        rep(i,0,k) {
            if(2+i >= 9) break;
            b[0] -= b[2+i];
        }
        rep(i,0,7) {
            if(2+i+k < 9) b[2+i] = b[2+i+k];
            else b[2+i] = 0;
        }
    }
    else {
        b[0] = a[0] * b[1];
        rep(i,2,9) b[i] = a[i]*b[1];
    }
    return b;
}

F composition(F a, F b) {
    if(a[0] != -1) return a;
    if(b[0] == -1){
        a[1] += b[1];
        return a;
    }
    ll k = a[1];
    rep(i,0,k) {
        if(2+i >= 9) break;
        b[0] -= b[2+i];
    }
    rep(i,0,7) {
        if(2+i+k < 9) b[2+i] = b[2+i+k];
        else b[2+i] = 0;
    }
    return b;
}

F id() {
    return {-1,0,0,0,0,0,0,0,0};
}

void solve(){
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(n);
    rep(i,0,n) {
        S res;
        ll x= a[i];
        res[0] = x;
        res[1] = 1;
        rep(i,2,9) {
            ll nx = sqrtll(x);
            res[i] = x - nx;
            x = nx;
        }
        seg.set(i, res);
    }
    
    while(q--) {
        int t;
        cin >> t;
        if(t == 0) {
            ll l,r;
            cin >> l >> r;
            cout << seg.prod(l, r)[0] << endl;
        }
        if(t == 1) {
            ll l,r,x;
            cin >> l >> r >> x;
            F res;
            res[0] = x;
            res[1] = 0;
            rep(i,2,9) {
                ll nx = sqrtll(x);
                res[i] = x - nx;
                x = nx;
            }
            seg.apply(l, r, res);
        }
        if(t == 2) {
            ll l,r;
            cin >> l >> r;
            F res = {-1,1,0,0,0,0,0,0,0};
            seg.apply(l, r, res);
        }

        // rep(i,0,n) cout << seg.get(i)[0] << " ";
        // cout << endl;
    }
}
0