結果

問題 No.876 Range Compress Query
ユーザー net
提出日時 2024-11-30 16:00:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 203,556 KB
最終ジャッジ日時 2025-02-26 09:39:39
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
#include<atcoder/lazysegtree>
using namespace atcoder;

struct S{
    ll a,l,r;
};
S op(S a, S b){
    if(a.a==-1) return b;
    if(b.a==-1) return a;

    S s;
    s.a=a.a+b.a;
    if(a.r!=b.l)s.a++;
    s.l=a.l;
    s.r=b.r;
    return s;
}
S e(){
    return S{-1,-1,-1};
}
using F = ll;
S mapping(F f, S s){
    s.l+=f;
    s.r+=f;
    return s;
}
F composition(F f, F g){
    return f+g;
}
F id(){
    return 0;
}

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

    int n,q;
    cin>>n>>q;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<S> init(n);
    rep(i,n){
        init[i].a=0;
        init[i].l=a[i];
        init[i].r=a[i];
    }
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(init);
    rep(qi,q){
        int t,l,r;
        cin>>t>>l>>r;
        l--;r--;
        if(t==1){
            int x;
            cin>>x;
            seg.apply(l,r+1,x);
        }
        if(t==2){
            cout<<seg.prod(l,r+1).a+1<<endl;
        }
    } 
    
}
0