Advertisement
gertsog

CPP V LS

Dec 18th, 2019
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. void precompute_hashes( std::string Str )
  2. {
  3.   const uint n = Str.size();
  4.  
  5.   Hi.resize(n);
  6.   Hi[0] = Str[0];
  7.   for (size_t i = 1; i < n; i++)
  8.     Hi[i] = Hi[i - 1] * x + static_cast<int64>(Str[i - 1]);
  9. }
  10.  
  11. inline int64 hash( uint l, uint r )
  12. {
  13.   return Hi[r] - Hi[l] * int64(powl(x, r - l));
  14. }
  15.  
  16. ....
  17. x = 31
  18. ...
  19. Ans.emplace_back(hash(a - 1, b - 1) == hash(c - 1, d - 1)
  20.     ? "Yes"
  21.     : "No");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement