結果

問題 No.1845 Long Substrings
ユーザー SSRSSSRS
提出日時 2022-02-18 22:20:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,111 bytes
コンパイル時間 2,754 ms
コンパイル使用メモリ 229,648 KB
実行使用メモリ 6,116 KB
最終ジャッジ日時 2023-09-11 19:26:53
合計ジャッジ時間 5,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
struct binary_indexed_tree{
  int N;
  vector<long long> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, long long x){
    i++;
    while (i <= N){
      BIT[i] += x;
      BIT[i] %= MOD;
      i += i & -i;
    }
  }
  long long sum(int i){
    long long ans = 0;
    while (i > 0){
      ans += BIT[i];
      ans %= MOD;
      i -= i & -i;
    }
    return ans;
  }
  long long sum(int L, int R){
    return (sum(R) - sum(L) + MOD) % MOD;
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  string S;
  cin >> S;
  vector<int> last(26, -1);
  binary_indexed_tree dp(N);
  for (int i = 0; i < N; i++){
    int c = S[i] - 'a';
    long long s;
    if (last[c] == -1){
      s = dp.sum(i);
    } else {
      s = dp.sum(last[c], i);
    }
    if (last[c] == -1){
      s++;
    }
    s %= MOD;
    s *= A[i];
    s %= MOD;
    dp.add(i, s);
    last[c] = i;
  }
  long long ans = dp.sum(0, N);
  cout << ans << endl;
}
0