Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- const long long p = 31;
- const long long mod = 1e9 + 7;
- void single_hash (string & s) {
- //~ long long hash_value = 0;
- //~ long long p_pow = 1;
- vector<long long> P;
- P.push_back(1LL);
- int n = (int) s.size();
- for (int i = 1; i < n; ++i) P.push_back((P.back() * p) % mod);
- //~ for (char c : s) {
- //~ hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
- //~ p_pow = (p_pow * p) % m;
- //~ }
- long long ulta_hash = 0,suja_hash = 0;
- vector<long long> pref_hash,suf_hash;
- for (int i = 0; i < n; ++i) {
- suja_hash = (suja_hash + (s[i] - 'a' + 1) * P[i]) % mod;
- pref_hash.push_back(suja_hash);
- }
- for (int i = n - 1; i >= 0; --i) {
- ulta_hash = (ulta_hash + (s[i] - 'a' + 1) * P[i]) % mod;
- suf_hash.push_back(ulta_hash);
- }
- for (int i = 0; i < n - 1; ++i) {
- cout << ((pref_hash[i] + suf_hash[i + 1]) % mod) << ' ';
- }
- cout << '\n';
- cout << ulta_hash << ' ' << suja_hash << '\n';
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string s = "aaaaa";
- single_hash(s);
- return 0;
- int T;
- cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement