結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー yuunegi
提出日時 2026-04-20 15:58:26
言語 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,343 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,784 ms
コンパイル使用メモリ 380,620 KB
実行使用メモリ 98,912 KB
最終ジャッジ日時 2026-04-20 16:00:27
合計ジャッジ時間 37,606 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 18 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#if __has_include("all.hpp")
#include "all.hpp"
#else
#include <atcoder/all>
#endif
using namespace atcoder;

//遅延セグ木・区間更新・区間和テンプレ

struct S{
    long long value;
    int size;
    int nowindex;
    array<long long,31>data;
};
struct F{
    int sd;
    //何回ルートをとるのか
    long long data;
};

S op(S a, S b){
    S tmp=a;
    tmp.value+=b.value;
    tmp.size+=b.size;
    tmp.nowindex=0;
    for(int i=0;i<31;i++){
        tmp.data[i]=a.data[min(a.nowindex+i,30)]+b.data[min(b.nowindex+i,30)];
    }
    return tmp; 
}
//データとデータの演算
S e(){
    array<long long, 31> tmp{};
    return {0, 0, 0,tmp};
}
//初期値(データ)
S mapping(F f, S x){
    if(f.data==-1){
        int bef=x.nowindex;
        x.nowindex=min(30,x.nowindex+f.sd);
        //cout<<bef<<" "<<x.nowindex<<" "<<f.sd<<endl;
        x.value-=x.data[bef]-x.data[x.nowindex];
        return x;
    }else{
        S tmp;
        tmp.data[0]=f.data;
        tmp.size=x.size;
        for(int i=0;i<30;i++){
            tmp.data[i+1]=((long long)sqrtl(tmp.data[i])*tmp.size);
        }
        tmp.nowindex=min(f.sd,30);
        tmp.value=tmp.data[tmp.nowindex];
        return tmp;
    }
    //return {x.value + f*x.size, x.size}; 
}
//データと演算子の演算
F composition(F f, F g){
    if(f.data!=-1){
        return f;
    }else{
        return {g.sd+f.sd,g.data};
    }
} 
//演算子と演算子の演算
F id(){ return {0,-1}; }
//初期値(演算子)

int main(void){
    int n,q;
    cin>>n>>q;
    vector<S>init;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        array<long long, 31> tmp;
        tmp[0]=a;
        for(int i=0;i<30;i++){
            tmp[i+1]=((long long)sqrtl(tmp[i]));
        }
        init.push_back({tmp[0],1,0,tmp});
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);
    while(q--){
        int o,l,r;
        cin>>o>>l>>r;
        if(o==0){
            cout<<seg.prod(l,r).value<<endl;
        }else if(o==1){
            int x;
            cin>>x;
            seg.apply(l,r,{0,x});
        }else if(o==2){
            seg.apply(l,r,{1,-1});
        }
        // for(int i=0;i<n;i++){
        //     cout<<seg.get(i).value<<" ";
        // }
        // cout<<endl;
    }
    return 0;
}
0