結果

問題 No.3239 Omnibus
ユーザー NyaanNyaan
提出日時 2025-08-15 22:07:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,701 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-15 22:08:14
合計ジャッジ時間 59,252 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30 WA * 2 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #


#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

#include <iostream>

#ifdef NyaanLocal
#include "misc/timer.hpp"
#endif
using namespace std;

int N, Q;
char S[200200], a[4];
int A[200200];

void update(int k) {
  if (0 <= k and k + 2 < N) A[k] = S[k] + (S[k + 1] << 8) + (S[k + 2] << 16);
}

/*
constexpr int B = 128;
long long query(int l, int r) {
  int x = a[0] + (a[1] << 8) + (a[2] << 16);
  int ans[B] = {}, bns[B] = {};
  int i = l;
  for (; i + B + 2 < r; i += B) {
#define f(j)                     \
  bool cond##j = x == A[i + j];  \
  ans[j] += cond##j ? i + j : 0; \
  bns[j] += cond##j ? 1 : 0;

    for (int j = 0; j < B; j++) {
      f(j);
    }
  }
  while (i + 2 < r) {
    bool cond = x == A[i];
    ans[0] += cond ? i : 0;
    bns[0] += cond ? 1 : 0;
    i++;
  }

  long long cns = 0, dns = 0;
  for (int b = 0; b < B; b++) cns += ans[b], dns += bns[b];
  return cns - dns * (l - 1);
}
*/

long long query(int l, int r) {
  int x = a[0] + (a[1] << 8) + (a[2] << 16);
  long long ans = 0;
  int bns = 0;
  for (int i = l; i + 2 < r; i++) {
    bool cond = x == A[i];
    ans += cond ? i : 0;
    bns += cond ? 1 : 0;
  }
  return ans - bns * (l - 1);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
#ifdef NyaanLocal
  Timer timer;
#endif
  cin >> N >> Q >> S;
  for (int i = 0; i + 2 < N; i++) update(i);
  while (Q--) {
    int cmd;
    cin >> cmd;
    if (cmd == 1) {
      int k;
      char x;
      cin >> k >> x;
      k--;
      S[k] = x;
      update(k - 2), update(k - 1), update(k);
    } else {
      int l, r;
      cin >> l >> r >> a;
      --l;
      cout << query(l, r) << "\n";
    }
  }
#ifdef NyaanLocal
  cerr << timer() << endl;
#endif
}
0