#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
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);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
31348 KB |
Output is correct |
2 |
Correct |
292 ms |
36308 KB |
Output is correct |
3 |
Correct |
274 ms |
36000 KB |
Output is correct |
4 |
Correct |
283 ms |
34928 KB |
Output is correct |
5 |
Correct |
307 ms |
36204 KB |
Output is correct |
6 |
Correct |
279 ms |
35300 KB |
Output is correct |
7 |
Correct |
292 ms |
36308 KB |
Output is correct |
8 |
Correct |
292 ms |
35408 KB |
Output is correct |
9 |
Correct |
284 ms |
35140 KB |
Output is correct |
10 |
Correct |
278 ms |
35408 KB |
Output is correct |
11 |
Correct |
289 ms |
35412 KB |
Output is correct |
12 |
Correct |
282 ms |
34384 KB |
Output is correct |
13 |
Correct |
293 ms |
35156 KB |
Output is correct |
14 |
Correct |
301 ms |
35924 KB |
Output is correct |
15 |
Correct |
292 ms |
35304 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
267 ms |
34524 KB |
Output is correct |
18 |
Correct |
274 ms |
34384 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3035 ms |
23124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3030 ms |
10596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
31348 KB |
Output is correct |
2 |
Correct |
292 ms |
36308 KB |
Output is correct |
3 |
Correct |
274 ms |
36000 KB |
Output is correct |
4 |
Correct |
283 ms |
34928 KB |
Output is correct |
5 |
Correct |
307 ms |
36204 KB |
Output is correct |
6 |
Correct |
279 ms |
35300 KB |
Output is correct |
7 |
Correct |
292 ms |
36308 KB |
Output is correct |
8 |
Correct |
292 ms |
35408 KB |
Output is correct |
9 |
Correct |
284 ms |
35140 KB |
Output is correct |
10 |
Correct |
278 ms |
35408 KB |
Output is correct |
11 |
Correct |
289 ms |
35412 KB |
Output is correct |
12 |
Correct |
282 ms |
34384 KB |
Output is correct |
13 |
Correct |
293 ms |
35156 KB |
Output is correct |
14 |
Correct |
301 ms |
35924 KB |
Output is correct |
15 |
Correct |
292 ms |
35304 KB |
Output is correct |
16 |
Correct |
4 ms |
8796 KB |
Output is correct |
17 |
Correct |
267 ms |
34524 KB |
Output is correct |
18 |
Correct |
274 ms |
34384 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Execution timed out |
3035 ms |
23124 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |