結果
問題 | No.2931 Shibuya 109 |
ユーザー |
![]() |
提出日時 | 2024-11-11 18:31:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 867 ms / 4,000 ms |
コード長 | 1,402 bytes |
コンパイル時間 | 2,062 ms |
コンパイル使用メモリ | 198,036 KB |
最終ジャッジ日時 | 2025-02-25 03:56:09 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/modint>using namespace std;//using namespace atcoder;using ll = long long;//using mint = modint998244353;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);/*09x->1+0x00x->0+0x01x->0+1x19x->2+1x10x->1+1x11x->1+2x29x->3+2x20x->2+2x21x->2+3x39x->4+3x30x->3+3x31x->3+4x1が出てくるごとにあまりが1増える(あまりは8以下)よって、1で挟まれた区間[l,r)の寄与は現在の余りをxとして(9の数) * (x+1) + (0の数) * x*/ll N, Q, A, l, r;cin >> N >> Q;vector<ll> S0(N+1), S9(N+1), p1;p1.push_back(0);for (int i=1; i<=N; i++){cin >> A;if (A == 1) p1.push_back(i);else if (A == 9) S9[i]++;else S0[i]++;S9[i] += S9[i-1];S0[i] += S0[i-1];}p1.push_back(N+1);while(Q--){cin >> l >> r;ll ans=0, cnt=0, l2, r2;for (int i=0; i<p1.size()-1; i++){r2 = min(p1[i+1]-1, r);l2 = max(p1[i], l);if (r2 >= l2){if (l2 == p1[i]) cnt++;ans += (S9[r2]-S9[l2-1]) * (cnt+1) + (S0[r2]-S0[l2-1]) * cnt + max(cnt-1, 0LL);}}cout << ans << endl;}return 0;}