結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー AK_Mi
提出日時 2026-04-21 21:54:45
言語 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
結果
TLE  
実行時間 -
コード長 2,291 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,654 ms
コンパイル使用メモリ 384,440 KB
実行使用メモリ 113,920 KB
最終ジャッジ日時 2026-04-21 21:56:38
合計ジャッジ時間 42,696 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using mint = modint998244353;
unsigned long long isqrt_aux(int c,unsigned long long n){
    if (c == 0){
        return 1;
    } else {
        int k = (c - 1) / 2;
        unsigned long long a = isqrt_aux(c / 2, n >> (2*k + 2));
        return (a << k) + (n >> (k+2)) / a;
    }
}

unsigned long isqrt(unsigned long long n){
    if (n == 0){
        return 0;
    } else {
        unsigned long long a = isqrt_aux(( 63 - __builtin_clzll(n)) / 2, n);
        return n <= a * a - 1 ? a - 1 : a;
    }
}

ll vsize = 32;
struct S{
    vector<ll> value;
    int size;
};
struct F{
    ll ch;
    ll sq;
};

const F ID = {-1,0};

S op(S a, S b){
    vector<ll> c(vsize,1);
    for(ll i = 0; i < vsize; i++){
        c[i] = a.value[i] + b.value[i];
    }
    return {c, a.size+b.size};
}
S e(){
    return {vector<ll>(vsize,0),0};
}
S mapping(F f, S x){
    if(f.ch != -1){
        x.value[0] = f.ch;
        for(ll i = 1; i < vsize; i++){
            x.value[i] = isqrt(x.value[i-1]);
        }
        for(ll i = 0; i < vsize; i++){
            x.value[i] *= x.size;
        }
    } 
    for(ll i = 0; i < vsize; i++){
        if(i + f.sq < vsize){
            x.value[i] = x.value[i + f.sq];
        }else{
            x.value[i] = x.size;
        }
    }
    return x;
}
F composition(F f, F g){
    F ret;
    if(f.ch != -1)ret = f;
    else ret = {g.ch, f.sq + g.sq};
    return ret;
}
F id(){ return ID; }

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

    ll n,q;
    cin >> n >> q;
    vector<ll> a(n,0);
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
    vector<ll> vec(vsize,1);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vec[0] = a[i];
        for(ll t = 1; t < vsize; t++){
            vec[t] = isqrt(vec[t-1]);
        }
        seg.set(i,{vec,1});
    }
    
    ll que,l,r,x;
    while(q--){
        cin >> que >> l >> r;
        if(que == 0){
            cout << seg.prod(l,r).value[0] << '\n';
        }else if(que == 1){
            cin >> x;
            seg.apply(l,r,{x,0});
        }else{
            seg.apply(l,r,{-1,1});
        }
    }

}
0