Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define nl '\n'
- #define cin(v) \
- for (auto &i : v) \
- cin >> i;
- #define cout(v) \
- for (auto &i : v) \
- cout << i << " "; \
- cout<<nl;
- #define br cout << '\n';
- #define ll long long
- #define ull unsigned long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 1000000007
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \
- << "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void solve()
- {
- ll n, q; cin>>n>>q;
- deque<ll> deq;
- map<ll, pair<ll,ll>> m;
- for(int i=0; i<n; i++){
- ll x; cin>>x;
- deq.push_back(x);
- }
- for(int i=1; i<=n*2; i++){
- ll f = deq.front();
- deq.pop_front();
- ll s = deq.front();
- deq.pop_front();
- m[i] = {f,s};
- if(f>s){
- deq.push_front(f);
- deq.push_back(s);
- }else{
- deq.push_front(s);
- deq.push_back(f);
- }
- }
- while(q--){
- ll target; cin>>target;
- if(target<=n)
- cout<<m[target].first<<' '<<m[target].second<<'\n';
- else
- cout<<m[(target - n) % (n-1) + n].first<<" "<<m[(target - n) % (n-1) + n].second<<'\n';
- }
- }
- int main()
- {
- Warding();
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- Time
- }
Advertisement
Add Comment
Please, Sign In to add comment