結果

問題 No.2931 Shibuya 109
ユーザー askr58
提出日時 2024-10-12 15:11:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,252 ms / 4,000 ms
コード長 821 bytes
コンパイル時間 5,420 ms
コンパイル使用メモリ 311,160 KB
実行使用メモリ 53,632 KB
最終ジャッジ日時 2024-10-12 15:12:17
合計ジャッジ時間 21,874 ms
ジャッジサーバーID
(参考情報)
judge5 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

struct S{
    ll sum,val,len;
    int p;
    S(){}
    S(ll sum,ll val,ll len,int p):sum(sum),val(val),len(len),p(p){};
};

S op(S x,S y){
    S res;
    res.sum=x.sum+y.sum+x.val*y.len;
    if(x.p==1)res.sum+=y.len;
    res.val=x.val+y.val;
    if(x.p==1)res.val++;
    res.len=x.len+y.len;
    res.p=y.p;
    return res;
}
S e(){
    return S(0,0,0,0);
}
int main()
{
    int n,q;
    cin>>n>>q;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<S> v(n);
    for(int i=0;i<n;i++){
        v[i]=S(0,0,1,a[i]);
        if(a[i]==9)v[i].sum++;
    }
    segtree<S,op,e> st(v);
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<st.prod(l-1,r).sum<<endl;
    }
    return 0;
}
0