orazma

b.cpp

May 18th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4. #define pb push_back
  5. #define mp make_pair
  6. #define ll long long
  7.  
  8. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  9.  
  10. using namespace std;
  11. const int INF = 1e9 + 10;
  12. const int MOD = 1e9 + 7;
  13. const int MOD2 = 1e9 + 9;
  14. const int MAXN = 2e6 + 10;
  15. int arr[MAXN];
  16.  
  17. pair <ll, ll> get_hash1(int l, int r){
  18.     return {(hash1[r] - hash1[l - 1] + MOD1) * st1[n - l] % MOD1,
  19.             (hash2[r] - hash2[l - 1] + MOD2) * st2[n - l] % MOD2};
  20. }
  21. pair <ll, ll> get_hash2(int l, int r){
  22.     return {(hash3[l] - hash3[r + 1] + MOD1) * st1[r - 1] % MOD1,
  23.             (hash4[l] - hash4[r + 1] + MOD2) * st2[r - 1] % MOD2};
  24. }
  25.  
  26. bool check(int l, int r){
  27.     return (get_hash1(l, r) == get_hash2(l, r));
  28. }
  29. void solve(){
  30.  
  31.     string s;
  32.     cin >> s;
  33.  
  34.     int n = s.size();
  35.     s = "#" + s;
  36.     st1[0] = 1;
  37.     for (int i = 1; i <= n; i++){
  38.         st1[i] = (st1[i - 1] * p1) % MOD1;
  39.         st2[i] = (st2[i - 1] * p2) % MOD2;
  40.     }
  41.     for (int i = 1; i <= n; i++){
  42.         hash1[i] = (hash1[i - 1] + st1[i] * (s[i] - 'a' + 1)) % MOD1;
  43.         hash2[i] = (hash2[i - 1] + st2[i] * (s[i] - 'a' + 1)) % MOD2;
  44.     }
  45.     for (int i = n, j = 1; i >= 1; i--, j++){
  46.         hash3[i] = (hash3[i + 1] + st1[j] * (s[i] - 'a' + 1)) % MOD1;
  47.         hash4[i] = (hash4[i + 1] + st2[j] * (s[i] - 'a' + 1)) % MOD2;
  48.     }
  49.  
  50.     ...
  51.  
  52.  
  53.     ...
  54.  
  55.  
  56.     cout << ans << "\n";
  57.  
  58.  
  59. }
  60.  
  61. int main() {
  62.     IOS;
  63.     int t = 1;
  64.     cin >> t;
  65.     while(t--){
  66.         solve();
  67.     }
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment