这个时候的数据已经很大很毒瘤了。自己改错过于困难qwq,有没有做过这题的分析一下原因。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,l,r) for(int i=l;i<=r;i++)
int n,Q;
const int N=1e5+10;
int a[N],pos,mx=-1;
const int M=3e5+10;
ll m[M];
struct node{int f,s;}ans[N];
deque<int>q;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>Q;
For(i,1,n){cin>>a[i];q.push_back(a[i]);mx=max(mx,a[i]);}
For(i,1,n){if(a[i]==mx){pos=i;break;}}
For(i,1,Q)cin>>m[i];
For(i,1,pos-1+n-1){
int fi=q.front();q.pop_front();
int se=q.front();q.pop_front();
ans[i].f=fi;ans[i].s=se;
if(fi>se)q.push_front(fi),q.push_back(se);
else q.push_front(se),q.push_back(fi);
}
//debug:id=0
For(i,1,Q){//循环周期为n-1
if(m[i]<=pos-1+n-1){cout<<ans[m[i]].f<<" "<<ans[m[i]].s<<"\n";continue;}
int x=(m[i]-(pos-1+n-1))%(n-1);//哪一组
if(x==0)x=n-1;
int id=pos-1+x;
cout<<ans[id].f<<" "<<ans[id].s<<"\n";
}
return 0;
}
//3 2
//1000000 999999 999998
//98
//999999999999
91338 82997
13746 61367 66962 32962 8522 64224 29214 28848 28341 45724 62777 57099 4715 86249 5454 87613 59821 75242 23064 42222 64864 82784 77165...
我的输出
91338 27307
91338 58863
91338 49783
91338 62716
91338 65262
91338 72236
91338 86859
91338 87217
91338 29702
...
答案输出
91338 50638
91338 70897
91338 17653
91338 85952
91338 47859
91338 42836
91338 4845
91338 90049
91338 13523
...