algo — C++23 日本語リファレンス GitHub

test/aoj/jag/rolling_hash.test.cpp

AC · 最終更新 2026-09-06 · GitHub

問題: https://onlinejudge.u-aizu.ac.jp/problems/2444

依存するヘッダ(2)
実装
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/2444
#include <iostream>
#include <string>
#include <unordered_set>
#include "string/hashint.hpp"
#include "string/rolling_hash.hpp"

int main(void) {
    int n, q;
    std::cin >> n >> q;
    std::string s, t;
    std::cin >> s;
    RollingHash rh(s);
    int l = 0, r = 1;
    std::unordered_set<HashInt> st;
    while (q--) {
        std::cin >> t;
        if (t == "L++") ++l;
        else if (t == "L--") --l;
        else if (t == "R++") ++r;
        else --r;
        st.emplace(rh.get(l, r));
    }
    std::cout << st.size() << '\n';

    return 0;
}