fork download
  1.  
  2. #define ll long long
  3. ll r(ll L, ll R) {
  4. assert(L <= R);
  5. assert(L >= LLONG_MIN && R <= LLONG_MAX);
  6. vector<ll>v = { LLONG_MIN,-9000000000000000000,-7000000000000000000,-5000000000000000000,-3000000000000000000,-1000000000000000000,-900000000000000000,-700000000000000000,-500000000000000000,-300000000000000000,-100000000000000000,-90000000000000000,-70000000000000000,-50000000000000000,-30000000000000000,-10000000000000000,-9000000000000000,-7000000000000000,-5000000000000000,-3000000000000000,-1000000000000000,-900000000000000,-700000000000000,-500000000000000,-300000000000000,-100000000000000,-90000000000000,-70000000000000,-50000000000000,-30000000000000,-10000000000000,-9000000000000,-7000000000000,-5000000000000,-3000000000000,-1000000000000,-900000000000,-700000000000,-500000000000,-300000000000,-100000000000,-90000000000,-70000000000,-50000000000,-30000000000,-10000000000,-9000000000,-7000000000,-5000000000,-3000000000,-1000000000,-900000000,-700000000,-500000000,-300000000,-100000000,-90000000,-70000000,-50000000,-30000000,-10000000,-9000000,-7000000,-5000000,-3000000,-1000000,-900000,-700000,-500000,-300000,-100000,-90000,-70000,-50000,-30000,-10000,-5000,-1000,-500,-100,-10,0,10,100,500,1000,5000,10000,30000,50000,70000,90000,100000,300000,500000,700000,900000,1000000,3000000,5000000,7000000,9000000,10000000,30000000,50000000,70000000,90000000,100000000,300000000,500000000,700000000,900000000,1000000000,3000000000,5000000000,7000000000,9000000000,10000000000,30000000000,50000000000,70000000000,90000000000,100000000000,300000000000,500000000000,700000000000,900000000000,1000000000000,3000000000000,5000000000000,7000000000000,9000000000000,10000000000000,30000000000000,50000000000000,70000000000000,90000000000000,100000000000000,300000000000000,500000000000000,700000000000000,900000000000000,1000000000000000,3000000000000000,5000000000000000,7000000000000000,9000000000000000,10000000000000000,30000000000000000,50000000000000000,70000000000000000,90000000000000000,100000000000000000,300000000000000000,500000000000000000,700000000000000000,900000000000000000,1000000000000000000,3000000000000000000,5000000000000000000,7000000000000000000,9000000000000000000 ,LLONG_MAX };
  7.  
  8.  
  9. // L operation
  10.  
  11.  
  12. /*
  13.   If L already exists in the array, get its index.
  14.   If not, insert L in its correct (sorted) position, then get its index.
  15.   In both cases, overwrite L with its index in the vector.
  16.   */
  17.  
  18. auto idx1 = lower_bound(v.begin(), v.end(), L);
  19. if (*idx1 != L)
  20. v.insert(idx1, L);
  21.  
  22. L = lower_bound(v.begin(), v.end(), L) - v.begin();
  23.  
  24.  
  25.  
  26.  
  27. // R operation
  28.  
  29. /*
  30.   Same idea as L: if R exists, get its index.
  31.   If not, insert R, then get its index.
  32.   Overwrite R with its index in the vector.
  33.   */
  34.  
  35. auto idx2 = lower_bound(v.begin(), v.end(), R);
  36. if (*idx2 != R)
  37. v.insert(idx2, R);
  38. R = lower_bound(v.begin(), v.end(), R) - v.begin();
  39.  
  40.  
  41.  
  42.  
  43. /*
  44.   imagine the above array like that
  45.   a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 . . . . .
  46.  
  47.   -> remember:
  48.   Now, L and R are indexes representing the range [L, R] in this sorted array.
  49.   We want to randomly pick a subinterval [newL, newR] within [L, R],
  50.   and finally choose a random value between v[newL] and v[newR].
  51.  
  52.   a1 a2 a3 a4 a5 a6 a7 a8 a9
  53.   ^ ^
  54.   L R
  55.  
  56.   we will pick any random interval(l,r) inside the above [L,R] interval like
  57.  
  58.   let the new random interval is
  59.   a1 a2 a3 a4 a5 a6 a7 a8 a9
  60.   ^ ^
  61.   L R
  62.   ^ ^
  63.   newL newR
  64.  
  65.   finally we will get any random value between a[newL] and a[newR]
  66.  
  67.   if you call r(0,1e9)
  68.   all what i did to to transform r(0,1e9) maybe to:
  69.   normal_random_fun(5000,90000)
  70.   normal_random_fun(0,5000)
  71.   normal_random_fun(3e8,9e8)
  72.   ....ect
  73.   */
  74.  
  75. ll newL, newR;
  76. // if you don't know what mt19937 is,until you search about it
  77. // you can think of it as something that generate a random number
  78.  
  79. newR = mt_rand(L, R);
  80. // this fun was made by mt19937 for longlong but now it work more effectively because of the small range
  81. newL = mt_rand(L, newR);
  82.  
  83.  
  84. return mt_rand(v[newL], v[newR]);
  85.  
  86. }
  87.  
  88.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘long long int r(long long int, long long int)’:
prog.cpp:4:3: error: ‘assert’ was not declared in this scope
   assert(L <= R);
   ^~~~~~
prog.cpp:4:3: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
prog.cpp:1:1:
+#include <cassert>
 
prog.cpp:4:3:
   assert(L <= R);
   ^~~~~~
prog.cpp:5:15: error: ‘LLONG_MIN’ was not declared in this scope
   assert(L >= LLONG_MIN && R <= LLONG_MAX);
               ^~~~~~~~~
prog.cpp:5:15: note: ‘LLONG_MIN’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 
prog.cpp:5:15:
   assert(L >= LLONG_MIN && R <= LLONG_MAX);
               ^~~~~~~~~
prog.cpp:5:33: error: ‘LLONG_MAX’ was not declared in this scope
   assert(L >= LLONG_MIN && R <= LLONG_MAX);
                                 ^~~~~~~~~
prog.cpp:5:33: note: ‘LLONG_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:6:3: error: ‘vector’ was not declared in this scope
   vector<ll>v = { LLONG_MIN,-9000000000000000000,-7000000000000000000,-5000000000000000000,-3000000000000000000,-1000000000000000000,-900000000000000000,-700000000000000000,-500000000000000000,-300000000000000000,-100000000000000000,-90000000000000000,-70000000000000000,-50000000000000000,-30000000000000000,-10000000000000000,-9000000000000000,-7000000000000000,-5000000000000000,-3000000000000000,-1000000000000000,-900000000000000,-700000000000000,-500000000000000,-300000000000000,-100000000000000,-90000000000000,-70000000000000,-50000000000000,-30000000000000,-10000000000000,-9000000000000,-7000000000000,-5000000000000,-3000000000000,-1000000000000,-900000000000,-700000000000,-500000000000,-300000000000,-100000000000,-90000000000,-70000000000,-50000000000,-30000000000,-10000000000,-9000000000,-7000000000,-5000000000,-3000000000,-1000000000,-900000000,-700000000,-500000000,-300000000,-100000000,-90000000,-70000000,-50000000,-30000000,-10000000,-9000000,-7000000,-5000000,-3000000,-1000000,-900000,-700000,-500000,-300000,-100000,-90000,-70000,-50000,-30000,-10000,-5000,-1000,-500,-100,-10,0,10,100,500,1000,5000,10000,30000,50000,70000,90000,100000,300000,500000,700000,900000,1000000,3000000,5000000,7000000,9000000,10000000,30000000,50000000,70000000,90000000,100000000,300000000,500000000,700000000,900000000,1000000000,3000000000,5000000000,7000000000,9000000000,10000000000,30000000000,50000000000,70000000000,90000000000,100000000000,300000000000,500000000000,700000000000,900000000000,1000000000000,3000000000000,5000000000000,7000000000000,9000000000000,10000000000000,30000000000000,50000000000000,70000000000000,90000000000000,100000000000000,300000000000000,500000000000000,700000000000000,900000000000000,1000000000000000,3000000000000000,5000000000000000,7000000000000000,9000000000000000,10000000000000000,30000000000000000,50000000000000000,70000000000000000,90000000000000000,100000000000000000,300000000000000000,500000000000000000,700000000000000000,900000000000000000,1000000000000000000,3000000000000000000,5000000000000000000,7000000000000000000,9000000000000000000 ,LLONG_MAX };
   ^~~~~~
prog.cpp:2:12: error: expected primary-expression before ‘long’
 #define ll long long
            ^~~~
prog.cpp:6:10: note: in expansion of macro ‘ll’
   vector<ll>v = { LLONG_MIN,-9000000000000000000,-7000000000000000000,-5000000000000000000,-3000000000000000000,-1000000000000000000,-900000000000000000,-700000000000000000,-500000000000000000,-300000000000000000,-100000000000000000,-90000000000000000,-70000000000000000,-50000000000000000,-30000000000000000,-10000000000000000,-9000000000000000,-7000000000000000,-5000000000000000,-3000000000000000,-1000000000000000,-900000000000000,-700000000000000,-500000000000000,-300000000000000,-100000000000000,-90000000000000,-70000000000000,-50000000000000,-30000000000000,-10000000000000,-9000000000000,-7000000000000,-5000000000000,-3000000000000,-1000000000000,-900000000000,-700000000000,-500000000000,-300000000000,-100000000000,-90000000000,-70000000000,-50000000000,-30000000000,-10000000000,-9000000000,-7000000000,-5000000000,-3000000000,-1000000000,-900000000,-700000000,-500000000,-300000000,-100000000,-90000000,-70000000,-50000000,-30000000,-10000000,-9000000,-7000000,-5000000,-3000000,-1000000,-900000,-700000,-500000,-300000,-100000,-90000,-70000,-50000,-30000,-10000,-5000,-1000,-500,-100,-10,0,10,100,500,1000,5000,10000,30000,50000,70000,90000,100000,300000,500000,700000,900000,1000000,3000000,5000000,7000000,9000000,10000000,30000000,50000000,70000000,90000000,100000000,300000000,500000000,700000000,900000000,1000000000,3000000000,5000000000,7000000000,9000000000,10000000000,30000000000,50000000000,70000000000,90000000000,100000000000,300000000000,500000000000,700000000000,900000000000,1000000000000,3000000000000,5000000000000,7000000000000,9000000000000,10000000000000,30000000000000,50000000000000,70000000000000,90000000000000,100000000000000,300000000000000,500000000000000,700000000000000,900000000000000,1000000000000000,3000000000000000,5000000000000000,7000000000000000,9000000000000000,10000000000000000,30000000000000000,50000000000000000,70000000000000000,90000000000000000,100000000000000000,300000000000000000,500000000000000000,700000000000000000,900000000000000000,1000000000000000000,3000000000000000000,5000000000000000000,7000000000000000000,9000000000000000000 ,LLONG_MAX };
          ^~
prog.cpp:18:27: error: ‘v’ was not declared in this scope
   auto idx1 = lower_bound(v.begin(), v.end(), L);
                           ^
prog.cpp:18:15: error: ‘lower_bound’ was not declared in this scope
   auto idx1 = lower_bound(v.begin(), v.end(), L);
               ^~~~~~~~~~~
prog.cpp:79:10: error: ‘mt_rand’ was not declared in this scope
   newR = mt_rand(L, R);
          ^~~~~~~
stdout
Standard output is empty