結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー yuunegi
提出日時 2026-04-20 15:32:30
言語 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,171 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,582 ms
コンパイル使用メモリ 383,524 KB
実行使用メモリ 117,080 KB
最終ジャッジ日時 2026-04-20 15:34:08
合計ジャッジ時間 28,370 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other WA * 7 TLE * 5 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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;
    vector<long long>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(){
    vector<long long>tmp(31,0);
    return {0, 1, 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.push_back(f.data);
        tmp.size=x.size;
        for(int i=0;i<30;i++){
            tmp.data.push_back((long long)sqrtl(tmp.data[i])*tmp.size);
        }
        tmp.nowindex=f.sd;
        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;
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        seg.apply(i,i+1,{0,a});
    }
    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