C

C - Valeriy and Deque

注意:vector<pair(int,int)> v;

放入元素:v.push_back(make_pair(a,b))

取元素:v[i].first,v[i].second.

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
queue<int> q;
vector<pair<int,int>> v1;
vector<pair<int,int>> v2;
#define ll long long
int main()
{
    int n,tt;
    scanf("%d%d",&n,&tt);
    int maxx=-0x3f3f3f3f;
    for(int i=1; i<=n; i++)
    {
        int t;
        scanf("%d",&t);
        maxx=max(maxx,t);
        q.push(t);
    }
    int cnt1=0;
    int f=q.front();
    q.pop();
//    printf("%d",maxx);
    while(q.size())
    {
        int t=q.front();
        q.pop();
//        printf("???");
        v1.push_back(make_pair(f,t));
        if(f>t)
        {
            q.push(t);
//            continue;
        }
        else
        {
            int temp=f;
            f=t;
            q.push(temp);
        }
//        printf("%d %d
",f,maxx);
        if(f==maxx)
        {
            break;
        }
    }
    for(int i=1; i<=n-1; i++)
    {
        int t=q.front();
        q.pop();
        v2.push_back(make_pair(f,t));
        q.push(t);
    }
    while(tt--)
    {
        ll t;
        scanf("%lld",&t);
        if(t<=v1.size())
        {
            printf("%d %d
",v1[t-1].first,v1[t-1].second);
            continue;
        }
        else
            t-=v1.size();
        t=t%v2.size();
        if(t==0) t=v2.size();
        printf("%d %d
",v2[t-1].first,v2[t-1].second);
    }
}

//3 2
//1000000 999999 999998
//98
//999999999999
原文地址:https://www.cnblogs.com/dongdong25800/p/11084377.html