This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fs first
#define sn second
#define N 1001000
using namespace std;
int n,m,x,y,z,now,sav,l,r,v[N],a[N],b[N],nx[N],sz[N],ans[N],p[N];
tuple<int,int,int>q[N];
stack<int>st;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
v[a[i]]=i;
}
for(int i=1;i<=m;++i){
scanf("%d%d",&x,&y);
q[i]=tie(x,y,i);
}
sort(q+1,q+1+m);
now=1;
for(int i=0;i<=n+2;++i){
while(now<=m&&get<0>(q[now])==i){
tie(x,y,z)=q[now];
ans[z]=a[y];
now++;
}
l=1;
r=n/2+1;
for(int j=1;j<=n;++j){
if((r>n)||(a[l]<a[r]&&l<=n/2))b[j]=a[l++];
else b[j]=a[r++];
}
for(int j=1;j<=n;++j)
a[j]=b[j];
}
while(now<=m){
tie(x,y,z)=q[now];
ans[z]=a[y];
now++;
}
for(int i=1;i<=m;++i)
printf("%d\n",ans[i]);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
Main.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |