#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int n,q;
int all[maxn],res[maxn],link[maxn];
set<int>st;
void solve(int v){
st.clear();
st.insert(n+1);
for(int i=1;i<=n;i++){
link[all[i]]=i;
}
int now=n;
for(int i=n;i>=1;i--){
//<<i<<endl;
auto x=*st.lower_bound(link[i]);
if(x==link[i])
{
continue;
}
int len=x-link[i];
//<<"salam2"<<endl;
int ted=now-(n/2);
//<<"salam3 "<<ted<<endl;
int z=0;
if(ted>0){
int f=min((len-1)/ted,v);
z=len-f*ted;
v-=f;
}
else{
z=len;
}
//<<len<<" "<<ted<<" "<<z<<endl;
for(int j=z-1;j>=0;j--){
//<<j<<" "<<link[i]<<" "<<all[link[i]+j]<<" "<<len<<" "<<now<<endl;
res[now]=all[link[i]+j];
st.insert(link[i]+j);
now--;
//<<"salam"<<endl;
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>all[i];
}
int u,v;
cin>>v>>u;
solve(v);
int lastv=v;
cout<<res[u]<<"\n";
for(int i=1;i<q;i++){
cin>>v>>u;
if(lastv!=v){
solve(v);
lastv=v;
}
cout<<res[u]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
261 ms |
18532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
6112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |