#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin(".in");
//ofstream cout(".out");
int n,q;
cin>>n>>q;
vi v(n);
f0r(i,n)cin>>v[i];
//f0r(i,n)cout<<v[i]<<' ';
//cout<<'\n';
vector<vi>ans;
ans.pb(v);
f0r(i,n){
vi v1;
vi v2;
f0r(j, n/2)v1.pb(v[j]);
f0r(j,n/2)v2.pb(v[j+n/2]);
int p1 = 0;
int p2 = 0;
vi a;
while(p1 < n/2 || p2 < n/2){
if(p1 == n/2){
a.pb(v2[p2]);
p2++;
}
else if(p2 == n/2){
a.pb(v1[p1]);
p1++;
}
else{
if(v1[p1] < v2[p2]){
a.pb(v1[p1]);
p1++;
}
else{
a.pb(v2[p2]);
p2++;
}
}
}
f0r(i,n)v[i] = a[i];
/*
f0r(i,n)cout<<v[i]<<' ';
cout<<'\n';
*/
ans.pb(v);
}
f0r(i,q){
int t,x;
cin>>t>>x;
x--;
if(t <= n)cout<<ans[t][x]<<'\n';
else cout<<ans[n][x]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
19792 KB |
Output is correct |
2 |
Correct |
153 ms |
19540 KB |
Output is correct |
3 |
Correct |
156 ms |
18772 KB |
Output is correct |
4 |
Correct |
134 ms |
17744 KB |
Output is correct |
5 |
Correct |
152 ms |
19128 KB |
Output is correct |
6 |
Correct |
148 ms |
17816 KB |
Output is correct |
7 |
Correct |
199 ms |
19280 KB |
Output is correct |
8 |
Correct |
137 ms |
17596 KB |
Output is correct |
9 |
Correct |
135 ms |
18256 KB |
Output is correct |
10 |
Correct |
136 ms |
17744 KB |
Output is correct |
11 |
Correct |
141 ms |
18260 KB |
Output is correct |
12 |
Correct |
129 ms |
16976 KB |
Output is correct |
13 |
Correct |
140 ms |
17488 KB |
Output is correct |
14 |
Correct |
143 ms |
18516 KB |
Output is correct |
15 |
Correct |
146 ms |
18004 KB |
Output is correct |
16 |
Correct |
8 ms |
8024 KB |
Output is correct |
17 |
Correct |
122 ms |
16952 KB |
Output is correct |
18 |
Correct |
129 ms |
16980 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
617 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
634 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
19792 KB |
Output is correct |
2 |
Correct |
153 ms |
19540 KB |
Output is correct |
3 |
Correct |
156 ms |
18772 KB |
Output is correct |
4 |
Correct |
134 ms |
17744 KB |
Output is correct |
5 |
Correct |
152 ms |
19128 KB |
Output is correct |
6 |
Correct |
148 ms |
17816 KB |
Output is correct |
7 |
Correct |
199 ms |
19280 KB |
Output is correct |
8 |
Correct |
137 ms |
17596 KB |
Output is correct |
9 |
Correct |
135 ms |
18256 KB |
Output is correct |
10 |
Correct |
136 ms |
17744 KB |
Output is correct |
11 |
Correct |
141 ms |
18260 KB |
Output is correct |
12 |
Correct |
129 ms |
16976 KB |
Output is correct |
13 |
Correct |
140 ms |
17488 KB |
Output is correct |
14 |
Correct |
143 ms |
18516 KB |
Output is correct |
15 |
Correct |
146 ms |
18004 KB |
Output is correct |
16 |
Correct |
8 ms |
8024 KB |
Output is correct |
17 |
Correct |
122 ms |
16952 KB |
Output is correct |
18 |
Correct |
129 ms |
16980 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Runtime error |
617 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |