結果

問題 No.2931 Shibuya 109
ユーザー t98slider
提出日時 2024-10-12 16:14:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 221 ms / 4,000 ms
コード長 592 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 196,216 KB
最終ジャッジ日時 2025-02-24 18:28:46
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, Q;
    cin >> n >> Q;
    vector<int> a(n), b, sv(n + 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sv[i + 1] = sv[i] + (a[i] == 9);
        if(a[i] == 1) b.emplace_back(i);
    }
    while(Q--){
        int l, r;
        cin >> l >> r;
        l--;
        int ans = sv[r] - sv[l];
        for(int i = 0; i < b.size() && b[i] < r; i++){
            if(b[i] < l) continue;
            ans += r - (b[i] + 1);
        }
        cout << ans << '\n';
    }
}
0