Korotkodul

DEBUG

Nov 20th, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. using ll = long long;
  9. void cv(vector <ll> v){
  10. for (auto x: v) cout<<x<<' ';
  11. cout<<'\n';
  12. }
  13.  
  14. ll inf = pow(2, 32);
  15. vector <ll> ar(1);
  16. vector <pair<ll,ll>> qr(1);
  17. struct sct{
  18. ll l, r, mn, mx;
  19. };
  20.  
  21. void csc(sct f){
  22. cout<<f.l<<'-'<<f.r<<'\n';
  23. cout<<f.mn<<'/'<<f.mx<<'\n';
  24. }
  25. vector <vector <sct> > wrk;
  26. int lvl = 1, lst_lvl;
  27. vector <sct> power;
  28. sct sm;
  29. void make(){
  30. int l,r;
  31. while (pow(2,lvl) <= ar.size()){
  32. lst_lvl = lvl / 2;
  33. int lst_lvl = pow(2, lst_lvl);
  34. //cout<<"lvl = "<<lvl<<'\n';
  35. vector <sct> last = wrk[wrk.size() - 1];
  36. //cv(ar);
  37. /*cout<<"last:\n";
  38. for (auto x: last) csc(x);
  39. cout<<'\n';*/
  40. int len = pow(2, lvl);
  41. int hlf = len / 2;
  42. for (int i = 0;i<=ar.size()-len;++i){
  43. //cv(ar);
  44. l = i;
  45. r = i + len - 1;
  46. //cout<<ar[l]<<' '<<ar[r]<<'\n';
  47. //cout<<"l = "<<l<<" r = "<<r<<'\n';
  48. sct L = last[l];
  49. sct R = last[l+hlf];
  50. sm = {l, r, min(L.mn, R.mn), max(L.mx, R.mx)};
  51. power.push_back(sm);
  52. /*csc(L);
  53. csc(R);
  54. csc(sm);
  55. cout<<'\n';*/
  56. }
  57. /*cout<<"power:\n";
  58. for (auto x: power){
  59. csc(x);
  60. }
  61. cout<<'\n';*/
  62. wrk.push_back(power);
  63. power.clear();
  64. //cout<<"sz = "<<wrk.size()<<'\n';
  65. //cout<<"\n\n\n\n";
  66. lvl++;
  67. }
  68. }
  69. int main()
  70. {
  71.  
  72. ll N,M,A,B;
  73. vector <ll> answer;
  74. vector <vector <ll> > miniS;
  75. vector <ll> mini;
  76. while (true){
  77. cin>>N>>M>>A>>B;
  78. //cin>>N>>M>>A>>B;
  79. if (N==0 && M==0 && A==0 && B==0) break;
  80. ar.clear();
  81. qr.clear();
  82. ll d;
  83. ll d1, d2;
  84. for (int i = 1;i<=N+M*2;++i){
  85. if (i <= N){
  86. d = ( ((A % inf) * (i % inf)) % inf + (B % inf) ) % inf;
  87. ar.push_back(d);
  88. /* cout<<d<<'\n';
  89. if (d == rl[i-1]) cout<<"OK\n";
  90. else cout<<"NO\n";*/
  91. }
  92. else{
  93. d1 = ( ((A % inf) * (i % inf)) % inf + (B % inf) ) % inf % N;
  94. d1++;
  95. i++;
  96. d2 = ( ((A % inf) * (i % inf)) % inf + (B % inf) ) % inf % N;
  97. d2++;
  98. qr.push_back({d1, d2});
  99. /*cout<<d1<<' '<<d2<<'\n';
  100. if (d1 == qr[id].first && d2 == qr[id].second){
  101. cout<<"OK\n";
  102. }else{
  103. cout<<"NO\n";
  104. }*/
  105. //id++;
  106. }
  107. }
  108. //cout<<'\n';
  109. //cv(ar);
  110. for (int i = 0; i < ar.size();++i){
  111. sm = {i, i, ar[i], ar[i]};
  112. //cout<<ar[i]<<'\n';
  113. //csc(sm);
  114. power.push_back(sm);
  115. }
  116. wrk.push_back(power);
  117. power.clear();
  118. //cout<<'\n'<<'\n';
  119. make();
  120. ll ans;
  121. ll tot = 0;
  122. mini.clear();
  123. for (auto Q: qr){
  124. int a = min(Q.first, Q.second);
  125. int b = max(Q.first, Q.second);
  126. a--;
  127. b--;
  128. //cout<<a<<' '<<b<<'\n';
  129. //cout<<b - a + 1<<'\n';
  130. int LVL = floor(log(b-a+1) / log(2));
  131. //cout<<"LVL = "<<LVL<<'\n';
  132. vector <sct> now = wrk[LVL];
  133. sct lft = now[a];
  134. sct rgt = now[b - pow(2,LVL) + 1];
  135. ans = min(lft.mn, rgt.mn);
  136. tot += ans;
  137. mini.push_back(ans);
  138. //cout<<a<<' '<<b - pow(2,LVL) + 1<<'\n'<<'\n';
  139. }//cout<<"tot="<<tot<<'\n';
  140. //cout<<tot<<'\n';
  141. cout<<"tot = "<<tot<<'\n';
  142. answer.push_back(tot);
  143. miniS.push_back(mini);
  144. }
  145. cout<<"ar:\n";
  146. cv(ar);
  147. cout<<"\n";
  148. cout<<"qr\n";
  149. for (auto x: qr) cout<<x.first<<' '<<x.second<<'\n';
  150. cout<<"\n";
  151. cout<<"miniS\n";
  152. for (auto x: miniS) cv(x);
  153. cout<<"\n";
  154. cout<<"answer\n";
  155. for (ll x: answer) cout<<x<<'\n';
  156. cout<<"\n";
  157. }
  158. /*
  159. 10 10 955379886 619166003
  160. */
  161.  
Add Comment
Please, Sign In to add comment