Advertisement
newb_ie

Untitled

Oct 15th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. const long long p = 31;
  5. const long long mod = 1e9 + 7;
  6.  
  7. void single_hash (string & s) {
  8. //~ long long hash_value = 0;
  9. //~ long long p_pow = 1;
  10. vector<long long> P;
  11. P.push_back(1LL);
  12. int n = (int) s.size();
  13. for (int i = 1; i < n; ++i) P.push_back((P.back() * p) % mod);
  14. //~ for (char c : s) {
  15. //~ hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
  16. //~ p_pow = (p_pow * p) % m;
  17. //~ }
  18. long long ulta_hash = 0,suja_hash = 0;
  19. vector<long long> pref_hash,suf_hash;
  20. for (int i = 0; i < n; ++i) {
  21. suja_hash = (suja_hash + (s[i] - 'a' + 1) * P[i]) % mod;
  22. pref_hash.push_back(suja_hash);
  23. }
  24. for (int i = n - 1; i >= 0; --i) {
  25. ulta_hash = (ulta_hash + (s[i] - 'a' + 1) * P[i]) % mod;
  26. suf_hash.push_back(ulta_hash);
  27. }
  28.  
  29. for (int i = 0; i < n - 1; ++i) {
  30. cout << ((pref_hash[i] + suf_hash[i + 1]) % mod) << ' ';
  31. }
  32. cout << '\n';
  33. cout << ulta_hash << ' ' << suja_hash << '\n';
  34. }
  35.  
  36. int main () {
  37. ios::sync_with_stdio(false);
  38. cin.tie(nullptr);
  39. cout.tie(nullptr);
  40. string s = "aaaaa";
  41. single_hash(s);
  42. return 0;
  43. int T;
  44. cin >> T;
  45. for (int test_case = 1; test_case <= T; ++test_case) {
  46.  
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement