Advertisement
tiom4eg

B2 63, heuristics

Jan 19th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define pll pair <ll, ll>
  12. #define vi vector <int>
  13. #define mi vector <vector <int> >
  14. // Quick functions
  15. #define endl "\n"
  16. #define F first
  17. #define S second
  18. #define all(a) a.begin(), a.end()
  19. #define sz(a) a.size()
  20. #define pb push_back
  21. #define mp make_pair
  22. #define fint(n) int n; cin >> n
  23. #define fstr(s) string s; cin >> s
  24. #define farr(a, n) int a[n]; for (int pog = 0; pog < n; ++pog) cin >> a[pog]
  25. #define min(a, b) ((a < b) ? (a) : (b))
  26. #define max(a, b) ((a > b) ? (a) : (b))
  27. // Quick fors
  28. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  29. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  30. // Pragmas
  31. #pragma GCC optimize("Ofast") // let the chaos begin!
  32. #pragma GCC optimize ("unroll-loops")
  33. #pragma target("avx,fma")
  34. #pragma comment(linker, "/stack:200000000")
  35. #pragma target("tune=native")
  36. // PBDS
  37. #include <ext/pb_ds/assoc_container.hpp>
  38. #include <ext/pb_ds/tree_policy.hpp>
  39. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  40. #define ook order_of_key
  41. #define fbo find_by_order
  42. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  43. using namespace std;
  44. using namespace __gnu_pbds;
  45. mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
  46.  
  47. const int LIM = 250000;
  48.  
  49. int gcd(int a, int b) {
  50.     while (a) {
  51.         b %= a;
  52.         swap(a, b);
  53.     }
  54.     return b;
  55. }
  56.  
  57. auto cmp = [](const pii& p1, const pii& p2) { return p1.F * 1LL * p2.S < p2.F * 1LL * p1.S; };
  58.  
  59. int main() { // heuristics
  60.     fastIO;
  61.     int n, q; cin >> n >> q;
  62.     vi a(n), b(n);
  63.     FOR(i, 0, n) cin >> a[i];
  64.     FOR(i, 0, n) cin >> b[i];
  65.     sort(all(a));
  66.     sort(all(b));
  67.     reverse(all(b));
  68.     vector <pii> g;
  69.     FOR(i, 0, n) FOR(j, 0, min(n, LIM / (i + 1))) g.pb({a[j], b[i]});
  70.     sort(all(g), cmp);
  71.     FOR(i, 0, q) {
  72.         ll p; cin >> p, p--;
  73.         int x = g[p].F, y = g[p].S;
  74.         cout << x / gcd(x, y) << ' ' << y / gcd(x, y) << endl;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement