#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
vector<int> v;
int ok = 0;
int n, q;
void mix(){
vector<int> novo;
int a = 0, b = n/2;
for(int i=0; i<n; i++){
if(a == -1) {novo.push_back(v[b]);b++;}
else if(b == -1){novo.push_back(v[a]); a++;}
else{
if(v[a] < v[b]){
novo.push_back(v[a]);
a++;
}
else{
novo.push_back(v[b]);
b++;
}
}
if(a >= n/2) a= -1;
if(b >= n) b = -1;
}
ok = 1;
for(int i=0; i<n; i++){
if(v[i] != novo[i]) ok = 0;
}
swap(novo, v);
return;
}
int main(){
cin >> n >> q;
v.resize(n);
for(int i=0; i<n; i++) cin >> v[i];
vector<iii> aux(q);
for(int i=0; i<q; i++){
int t,pos; cin >> t >> pos;
aux[i] = {{t,pos}, i};
}
sort(aux.begin(), aux.end());
vector<int> res(q);
int t = 0;
for(auto [a,b] : aux){
auto [tt, pos] = a;
while(t!= tt and ok == 0){
mix();
t++;
}
res[b] = v[pos-1];
}
for(auto i: res) cout << i << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1497 ms |
20100 KB |
Output is correct |
2 |
Correct |
1486 ms |
19796 KB |
Output is correct |
3 |
Correct |
1483 ms |
19052 KB |
Output is correct |
4 |
Correct |
1416 ms |
19048 KB |
Output is correct |
5 |
Correct |
1531 ms |
19792 KB |
Output is correct |
6 |
Correct |
1447 ms |
19036 KB |
Output is correct |
7 |
Correct |
1540 ms |
19816 KB |
Output is correct |
8 |
Correct |
1425 ms |
19104 KB |
Output is correct |
9 |
Correct |
1498 ms |
18860 KB |
Output is correct |
10 |
Correct |
1496 ms |
19284 KB |
Output is correct |
11 |
Correct |
1439 ms |
19296 KB |
Output is correct |
12 |
Correct |
1457 ms |
18996 KB |
Output is correct |
13 |
Correct |
1441 ms |
19376 KB |
Output is correct |
14 |
Correct |
1455 ms |
19640 KB |
Output is correct |
15 |
Correct |
1473 ms |
19956 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1442 ms |
19268 KB |
Output is correct |
18 |
Correct |
1430 ms |
19404 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
18732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3031 ms |
3260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1497 ms |
20100 KB |
Output is correct |
2 |
Correct |
1486 ms |
19796 KB |
Output is correct |
3 |
Correct |
1483 ms |
19052 KB |
Output is correct |
4 |
Correct |
1416 ms |
19048 KB |
Output is correct |
5 |
Correct |
1531 ms |
19792 KB |
Output is correct |
6 |
Correct |
1447 ms |
19036 KB |
Output is correct |
7 |
Correct |
1540 ms |
19816 KB |
Output is correct |
8 |
Correct |
1425 ms |
19104 KB |
Output is correct |
9 |
Correct |
1498 ms |
18860 KB |
Output is correct |
10 |
Correct |
1496 ms |
19284 KB |
Output is correct |
11 |
Correct |
1439 ms |
19296 KB |
Output is correct |
12 |
Correct |
1457 ms |
18996 KB |
Output is correct |
13 |
Correct |
1441 ms |
19376 KB |
Output is correct |
14 |
Correct |
1455 ms |
19640 KB |
Output is correct |
15 |
Correct |
1473 ms |
19956 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1442 ms |
19268 KB |
Output is correct |
18 |
Correct |
1430 ms |
19404 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3068 ms |
18732 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |