Korotkodul

K5 debug debug

Jan 13th, 2022 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31. string S;
  32.  
  33. int n;
  34.  
  35. vector <ll> pf, lvp;
  36.  
  37. const int p = 29, mod = 1e9 + 7;
  38.  
  39.  
  40. int nm(char x){
  41. return x - 'a' + 1;
  42. }
  43.  
  44. ll H(int l, int r){
  45. ll k = r - l + 1;
  46. ll res = pf[r];
  47. if (l > 0){
  48. res -= pf[l-1] * lvp[k] % mod;
  49. }
  50. if (res < 0) res += mod;
  51. return res;
  52. }
  53.  
  54.  
  55.  
  56. int l1, r1, l2, r2;
  57.  
  58. int cmp(){
  59. int lf, rt, md;
  60. //бинописком ищем длину наибольшего общего префикса
  61. lf = 0;
  62. rt = min(r2 - l2, r1 - l1);
  63. //cout<<"lf rt = "<<lf<<' '<<rt<<"\n";
  64. //cout<<"l r = "<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<"\n";
  65. while (rt - lf > 1){
  66. md = (lf + rt) / 2;
  67. ll a,b;
  68. a = H(l1, l1 + md);
  69. b = H(l2, l2 + md);
  70. //cout<<"md = "<<md<<"\n";
  71. //cout<<"a b = "<<a<<' '<<b<<"\n";
  72. if (a == b){
  73. lf = md;
  74. }
  75. else rt= md;
  76. }
  77. //cout<<"rt = "<<rt<<"\n";
  78. rt--;
  79. if (rt<0)rt=0;
  80. while (S[l1+rt]==S[l2+rt] && l1 + rt <= r1 && l2 + rt <= r2) rt++;
  81. //cout<<"rt = "<<rt<<"\n";
  82. if (l1 + rt > r1 && l2 + rt > r2){
  83. return 0;
  84. }
  85. if (l1 + rt > r1) {
  86. return -1;
  87. }
  88. if (l2 + rt > r2){
  89. return 1;
  90. }
  91. if (S[l1 + rt] > S[l2 + rt]){
  92. //cout<<"four\n";
  93. return 1;
  94. }
  95. if (S[l1 + rt] < S[l2 + rt]){
  96. //cout<<"five\n";
  97. return -1;
  98. }
  99. if (S[l1 + rt] == S[l2 + rt]){
  100. //cout<<"six\n";
  101. return 0;
  102. }
  103. }
  104.  
  105. string rndS(){
  106. string res = "";
  107. int sz = rand() % 100 + 20;
  108. string alp = "abcdefghijklmnopqrstuvwxyz";
  109. for (int i = 0;i < sz;++i){
  110. int id = rand() % alp.size();
  111. res += alp[id];
  112. }
  113. return res;
  114. }
  115.  
  116. int stp(){
  117. string a,b;
  118. a = S.substr(l1, r1 - l1 + 1);
  119. b = S.substr(l2, r2 - l2 + 1);
  120. if (a > b){
  121. return 1;
  122. }
  123. if (a < b){
  124. return -1;
  125. }
  126. return 0;
  127. }
  128.  
  129. void cpr(pii x){
  130. cout<<x.first<<' '<<x.second<<"\n";
  131. }
  132.  
  133.  
  134. int main()
  135. {
  136. //ios::sync_with_stdio(0);
  137. //cin.tie(0);
  138. //cout.tie(0);
  139. //cin>>S;
  140. S = rndS();
  141. n = S.size();
  142. lvp.assign(n+5, 1);
  143. for (int i = 1; i<=n;++i) lvp[i] = lvp[i-1] * p % mod;
  144. pf.assign(n, nm(S[0]));
  145. for (int i =1;i<n;++i){
  146. pf[i] = (pf[i-1] * p % mod + nm(S[i])) % mod;
  147. }
  148. //int q; cin>>q;
  149. int ans;
  150. cout<<S<<"\n";
  151. vector <vector<int>> lr;
  152. vector <pii> checker;
  153. int go=0;
  154. while (1){
  155. go++;
  156. //cin>>l1>>r1>>l2>>r2;
  157. l1 = rand() % S.size();
  158. if (go > 2e6){
  159. cout<<"NOT FOUND\n";
  160. break;
  161. }
  162. r1 = l1 + rand() % (n - l1);
  163. if (r1 < l1) r1=l1;
  164. if (r1 >= n) r1=n-1;
  165. l2 = rand() % S.size();
  166. r2 = l2 + rand() % (n - l2);
  167. if (r2 < l2) r2=l2;
  168. if (r2>=n) r2=n-1;
  169. ans = cmp();
  170. int chk = stp();
  171. //cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<"\n";
  172. //cout<<"ans = "<<ans<<"\n";
  173. //cout<<ans<<"\n";
  174. if (ans != chk){
  175. //cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<"\n";
  176. //cout<<"ans= "<<ans<<"\n";
  177. //cout<<"chk= "<<chk<<"\n";
  178. vector <int> v = {l1, r1, l2, r2};
  179. lr.push_back(v);
  180. checker.push_back({ans, chk});
  181. }
  182. if (checker.size() >= 10) break;
  183. }
  184. cout<<"CHECKING DONE\n";
  185. for (int i=0;i<checker.size();++i){
  186. cv(lr[i]);
  187. cpr(checker[i]);
  188. cout<<"\n";
  189. }
  190. /*int go=0;
  191. S = "hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvyst";
  192. while (1){
  193. cin>>l1>>r1>>l2>>r2;
  194. go++;
  195. if (l1==-1 && l2==-1 && r1==-1 && r2==-1) break;
  196. string a = S.substr(l1, r1 - l1 + 1);
  197. string b = S.substr(l2, r2 - l2 + 1);
  198. cout<<a<<' '<<b<<"\n";
  199. }*/
  200. //мой ответ - верный ответ
  201. //1 сравниваешь но не учитываешь размер
  202. }
  203. /*
  204. hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvyst
  205. CHECKING DONE
  206. 58 59 58 60
  207. 0 -1
  208.  
  209. 17 59 56 56
  210. 0 1
  211.  
  212. 4 8 4 25
  213. 0 -1
  214.  
  215. 19 52 19 19
  216. 0 1
  217.  
  218. 40 44 40 42
  219. 0 1
  220.  
  221. 23 59 23 46
  222. 0 1
  223.  
  224. 23 46 51 51
  225. 0 1
  226.  
  227. 35 47 35 51
  228. 0 -1
  229.  
  230. 10 39 29 29
  231. 0 1
  232.  
  233. 15 32 12 12
  234. 0 1
  235. */
  236.  
Add Comment
Please, Sign In to add comment