Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <map>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cmath>
  9. #include <set>
  10. #include <unordered_set>
  11. #include <stack>
  12. #include <cassert>
  13. #include <queue>
  14. #include <deque>
  15.  
  16. using namespace std;
  17.  
  18. typedef long long ll;
  19. typedef long double ld;
  20.  
  21. //const int inf=1e9+1329;
  22. //#define int long long
  23.  
  24. //для одной строки
  25. const ll MOD_1=1e9+1329;
  26. const ll MOD_2=1e9-239;
  27.  
  28. const ll BASE_1=239;
  29. const ll BASE_2=1329;
  30.  
  31. vector<ll> base_pow_1;
  32. vector<ll> base_pow_2;
  33.  
  34. vector<ll> h_1;
  35. vector<ll> h_2;
  36.  
  37. string s;
  38.  
  39. void precalc(){
  40. int n=(int)s.size();
  41. base_pow_1.resize(n+1);
  42. base_pow_2.resize(n+1);
  43. h_1.resize(n+1);
  44. h_2.resize(n+1);
  45. base_pow_1[0]=1;
  46. base_pow_2[0]=1;
  47. h_1[0]=0;
  48. h_2[0]=0;
  49. for(int i=0;i<n;i++){
  50. h_1[i+1]=(h_1[i] * BASE_1 + (s[i] - 'a')) % MOD_1;
  51. h_2[i+1]=(h_2[i] * BASE_2 + (s[i] - 'a')) % MOD_2;
  52. base_pow_1[i+1]=(base_pow_1[i] * BASE_1) % MOD_1;
  53. base_pow_2[i+1]=(base_pow_2[i] * BASE_2) % MOD_2;
  54. }
  55. return;
  56. }
  57.  
  58. ll get_hash_1(int l,int r){
  59. return h_1[r] - h_1[l] * base_pow_1[r-l];
  60. }
  61.  
  62. ll get_hash_2(int l,int r){
  63. return h_2[r] - h_2[l] * base_pow_2[r-l];
  64. }
  65.  
  66. bool equal(int fl,int fr,int sl,int sr){
  67. if(fr-fl!=sr-sl){
  68. return false;
  69. }
  70. ll tmp_1=get_hash_1(fl, fr) - get_hash_1(sl, sr);
  71. ll tmp_2=get_hash_2(fl, fr) - get_hash_2(sl, sr);
  72. return tmp_1%MOD_1==0 && tmp_2%MOD_2==0;
  73. }
  74.  
  75.  
  76. vector<int> slv(string cur){
  77. vector<int> ans;
  78. s=cur;
  79. precalc();
  80. int n=s.size();
  81. vector<int> fact;
  82. for(int i=1;i<=n;i++){
  83. if(n%i==0){
  84. fact.push_back(i);
  85. }
  86. }
  87. for(auto cur:fact){
  88. bool fl=1;
  89. for(int i=0;i+1<n/cur;i++){
  90. if(!equal(cur*i,cur*(i+1),cur*(i+1),cur*(i+2))){
  91. fl=0;
  92. }
  93. }
  94. if(fl){
  95. ans.push_back(cur);
  96. }
  97. }
  98. return ans;
  99. }
  100. //
  101.  
  102. signed main() {
  103. ios_base::sync_with_stdio(false);
  104. cin.tie(0);
  105.  
  106. #ifndef ONLINE_JUDGE
  107. freopen("input.txt", "r", stdin);
  108. freopen("output.txt", "w", stdout);
  109. #endif
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement