fork(1) download
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int n, d, X, A[110000], B[110000], q[110000], to[110000];
  8. int pu;
  9.  
  10. int getNextX() {
  11. X = (X * 37LL + 10007) % 1000000007;
  12. return X;
  13. }
  14.  
  15. int main() {
  16. scanf("%d%d%d", &n, &d, &X);
  17. for (int i = 0; i < n; i = i + 1)
  18. A[i] = i + 1;
  19. for (int i = 0; i < n; i = i + 1)
  20. swap(A[i], A[getNextX() % (i + 1)]);
  21. for (int i = 0; i < n; i = i + 1) {
  22. if (i < d)
  23. B[i] = 1;
  24. else
  25. B[i] = 0;
  26. }
  27. for (int i = 0; i < n; i = i + 1)
  28. swap(B[i], B[getNextX() % (i + 1)]);
  29. for (int i = 0; i < n; i++) if (B[i]) q[++q[0]] = i;
  30.  
  31. int s = 30;
  32.  
  33. for (int i = 0; i < n; i++) to[A[i]] = i;
  34.  
  35. for (int i = 0; i < n; i++) {
  36. int j;
  37. for (j = n; j >= n - s; j--)
  38. if (j > 0 && i >= to[j] && B[i - to[j]]) {
  39. printf("%d\n", j);
  40. break;
  41. }
  42. if (j < n - s) {
  43. int ma = 0;
  44. for (j = 1; j <= q[0] && q[j] <= i; j++)
  45. ma = max(ma, A[i - q[j]]);
  46. printf("%d\n", ma);
  47. }
  48. }
  49. }
  50.  
Success #stdin #stdout 0s 5012KB
stdin
Standard input is empty
stdout
Standard output is empty