#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e5 + 10 ;
int arr[MAX] ;
int n , q ;
vector<int>v ;
vector<int>ans[MAX] ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>q ;
v.resize(n) ;
for(auto &x : v)
cin>>x ;
ans[0] = v ;
int last = 0 ;
for(int k = 1 ; ; ++k)
{
vector<int>v2[2] ;
for(int i = n-1 ; i >= 0 ; --i)
v2[(i >= n/2)].push_back(ans[k-1][i]) ;
for(int i = 0 ; i < n ; ++i)
{
bool t = 0 ;
if((!v2[0].size()) || (v2[1].size() && v2[0].back() > v2[1].back()))
t = 1 ;
ans[k].push_back(v2[t].back()) ;
v2[t].pop_back() ;
}
last = k ;
if(ans[k] == ans[k-1])
break ;
}
while(q--)
{
int t , idx ;
cin>>t>>idx ;
t = min(t , last) ;
cout<<ans[t][idx-1]<<"\n" ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
18180 KB |
Output is correct |
2 |
Correct |
174 ms |
14908 KB |
Output is correct |
3 |
Correct |
173 ms |
15616 KB |
Output is correct |
4 |
Correct |
167 ms |
12584 KB |
Output is correct |
5 |
Correct |
186 ms |
14364 KB |
Output is correct |
6 |
Correct |
152 ms |
13200 KB |
Output is correct |
7 |
Correct |
174 ms |
14472 KB |
Output is correct |
8 |
Correct |
147 ms |
13160 KB |
Output is correct |
9 |
Correct |
167 ms |
12756 KB |
Output is correct |
10 |
Correct |
154 ms |
13132 KB |
Output is correct |
11 |
Correct |
157 ms |
13116 KB |
Output is correct |
12 |
Correct |
154 ms |
11964 KB |
Output is correct |
13 |
Correct |
157 ms |
12640 KB |
Output is correct |
14 |
Correct |
160 ms |
13672 KB |
Output is correct |
15 |
Correct |
156 ms |
12920 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
141 ms |
12076 KB |
Output is correct |
18 |
Correct |
148 ms |
11980 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1846 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1753 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
18180 KB |
Output is correct |
2 |
Correct |
174 ms |
14908 KB |
Output is correct |
3 |
Correct |
173 ms |
15616 KB |
Output is correct |
4 |
Correct |
167 ms |
12584 KB |
Output is correct |
5 |
Correct |
186 ms |
14364 KB |
Output is correct |
6 |
Correct |
152 ms |
13200 KB |
Output is correct |
7 |
Correct |
174 ms |
14472 KB |
Output is correct |
8 |
Correct |
147 ms |
13160 KB |
Output is correct |
9 |
Correct |
167 ms |
12756 KB |
Output is correct |
10 |
Correct |
154 ms |
13132 KB |
Output is correct |
11 |
Correct |
157 ms |
13116 KB |
Output is correct |
12 |
Correct |
154 ms |
11964 KB |
Output is correct |
13 |
Correct |
157 ms |
12640 KB |
Output is correct |
14 |
Correct |
160 ms |
13672 KB |
Output is correct |
15 |
Correct |
156 ms |
12920 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
141 ms |
12076 KB |
Output is correct |
18 |
Correct |
148 ms |
11980 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Runtime error |
1846 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |