fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MX = 100005;
  5. int n;
  6. int a[MX], b[MX];
  7. long long f[MX];
  8. vector<int> A[MX], B[MX];
  9.  
  10. long long count(int u, int mid) {
  11. long long res = 0;
  12. for(int i = 0, j = 0; i < (int)A[u].size(); ++i) {
  13. while(j < B[u].size() && B[u][j] + mid <= A[u][i]) ++j;
  14. res += j;
  15. }
  16. for(int i = 0, j = 0; i < (int)B[u].size(); ++i) {
  17. while(j < A[u].size() && A[u][j] + mid <= B[u][i]) ++j;
  18. res += j;
  19. }
  20. return res;
  21. }
  22.  
  23. bool check(int mid, int x) {
  24. for(int i = x; i <= n; i += x) f[i] = 0;
  25. for(int i = x; i <= n; i += x) f[i] = count(i, mid);
  26. for(int i = x * (n / x); i >= x; i -= x) {
  27. for(int j = i << 1; j <= n; j += i) {
  28. f[i] -= f[j];
  29. }
  30. }
  31. return f[x];
  32. }
  33.  
  34. int32_t main() {
  35. ios_base::sync_with_stdio(false);
  36. cin.tie(0);
  37.  
  38. cin >> n;
  39. for(int i = 1; i <= n; ++i) cin >> a[i];
  40. for(int i = 1; i <= n; ++i) cin >> b[i];
  41. for(int i = 1; i <= n; ++i) {
  42. for(int j = i; j <= n; j += i) {
  43. A[i].push_back(a[j]);
  44. B[i].push_back(b[j]);
  45. }
  46. sort(A[i].begin(), A[i].end());
  47. sort(B[i].begin(), B[i].end());
  48. }
  49. for(int i = 1; i <= n; ++i) {
  50. int res = 0;
  51. for(int lo = 0, hi = 1e9; lo <= hi;) {
  52. int mid = (lo + hi) >> 1;
  53. if(check(mid, i)) res = mid, lo = mid + 1;
  54. else hi = mid - 1;
  55. }
  56. cout << res << " ";
  57. }
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 8272KB
stdin
Standard input is empty
stdout
Standard output is empty