Korotkodul

OK спарсы

Nov 30th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 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. using unt = unsigned int;
  10. void cv(vector <unt> v){
  11. for (auto x: v) cout<<x<<' ';
  12. cout<<'\n';
  13. }
  14.  
  15. vector <unt> level(65);
  16. //степень - массив
  17. unt N=1,M=1,A=1,B=1;
  18. vector <vector <unt> > wrk(15, vector <unt> (25000));
  19. vector <unt> ar(25000);
  20. void make(unt &mx_lvl){
  21. //cout<<"making wrk\n";
  22. //for (int i=0;i<N;++i) cout<<wrk[0][i]<<' ';
  23. //cout<<"\n";
  24. for (unt i = 1; i <= mx_lvl; ++i){
  25. unt till = N - level[i];
  26. //cout<<"N= "<<N<<"\n";
  27. //cout<<"i= "<<i<<" level[i]= "<<level[i]<<" till= "<<till<<"\n";
  28. for (unt j = 0; j <= till ; ++j){
  29. //cout<<"j= "<<j<<"\n";
  30. unt l = j;
  31. unt r = j + level[i-1];
  32. unt L = wrk[i-1][l];
  33. unt R = wrk[i-1][r];
  34. //cout<<"lr= "<<l<<" "<<r<<"\n";
  35. //cout<<"LR= "<<L<<" "<<R<<"\n";
  36. wrk[i][j] = min(L, R);
  37. //cout<<"wrk[i][j]= "<<wrk[i][j]<<"\n";
  38. }
  39. //for (int h = 0; h <= till;++h) cout<<wrk[i][h]<<' ';
  40. //cout<<"\n";
  41. }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. ios::sync_with_stdio(0);
  48. cin.tie(0);
  49. cout.tie(0);
  50. for (int i = 0;i<65;++i){
  51. level[i] = pow(2,i);
  52. }
  53.  
  54. while (true){
  55. cin>>N>>M>>A>>B;
  56. if (N==0 && M==0 && A==0 && B==0) break;
  57. unt d;
  58. unt a,b;
  59. //cout<<"make sequence\n";
  60. for (int i = 1;i<=N;++i){
  61. d = A * i + B;
  62. //ar.push_back(d);
  63. ar[i-1] = d;
  64. wrk[0][i-1]=d;
  65. }
  66. unt mx_lvl = log2(N);
  67. //cout<<"let's make wrk\n";
  68. make(mx_lvl);
  69. //cout<<"wrk MADE\n";
  70. ll ans;
  71. ll tot = 0;
  72. /*cout<<"qr:\n";
  73. for (auto x: qr) cout<<x.first<<' '<<x.second<<'\n';
  74. cout<<'\n';*/
  75. //в степень - массив
  76. /*cout<<"ar\n";
  77. for (int i=0;i<N;++i) cout<<ar[i]<<' ';
  78. cout<<"\n";*/
  79. for (unt i = N+1;i<=N+M*2;++i){
  80. a = (A * i + B);
  81. a %= N;
  82. //a++;
  83. i++;
  84. b = (A * i + B);
  85. b %= N;
  86. if (a > b) swap(a, b);
  87. //b++;
  88. //cout<<"ab= "<<a<<" "<<b<<"\n";
  89. unt LVL = log2(b-a+1);
  90. ll lft = wrk[LVL][a];
  91. ll rgt = wrk[LVL][b - level[LVL] + 1];
  92. ans = min(lft, rgt);
  93. //cout<<"ans= "<<ans<<'\n';
  94. tot += ans;
  95. }
  96. cout<<tot<<"\n";
  97. }
  98. //cout<<"p= "<<p<<'\n';
  99. }
  100. /*
  101. 25000 20000000 1000000000 1000000000
  102. 0 0 0 0
  103. */
Add Comment
Please, Sign In to add comment