Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define pll pair <ll, ll>
- #define vi vector <int>
- #define mi vector <vector <int> >
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) a.size()
- #define pb push_back
- #define mp make_pair
- #define fint(n) int n; cin >> n
- #define fstr(s) string s; cin >> s
- #define farr(a, n) int a[n]; for (int pog = 0; pog < n; ++pog) cin >> a[pog]
- #define min(a, b) ((a < b) ? (a) : (b))
- #define max(a, b) ((a > b) ? (a) : (b))
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- // Pragmas
- #pragma GCC optimize("Ofast") // let the chaos begin!
- #pragma GCC optimize ("unroll-loops")
- #pragma target("avx,fma")
- #pragma comment(linker, "/stack:200000000")
- #pragma target("tune=native")
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
- const int LIM = 250000;
- int gcd(int a, int b) {
- while (a) {
- b %= a;
- swap(a, b);
- }
- return b;
- }
- auto cmp = [](const pii& p1, const pii& p2) { return p1.F * 1LL * p2.S < p2.F * 1LL * p1.S; };
- int main() { // heuristics
- fastIO;
- int n, q; cin >> n >> q;
- vi a(n), b(n);
- FOR(i, 0, n) cin >> a[i];
- FOR(i, 0, n) cin >> b[i];
- sort(all(a));
- sort(all(b));
- reverse(all(b));
- vector <pii> g;
- FOR(i, 0, n) FOR(j, 0, min(n, LIM / (i + 1))) g.pb({a[j], b[i]});
- sort(all(g), cmp);
- FOR(i, 0, q) {
- ll p; cin >> p, p--;
- int x = g[p].F, y = g[p].S;
- cout << x / gcd(x, y) << ' ' << y / gcd(x, y) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement