#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, q, shuffle, card, index, shuffles=0, t=0, i;
cin >> n >> q;
int a[n], answer[q]={0};
tuple<int, int, int> queries[q];
vector<int> left, right;
for (i=0; i<n; i++)
cin >> a[i];
for (i=0; i<q; i++)
{
int shuffle, card;
cin >> shuffle >> card;
queries[i]={shuffle, card, i};
}
sort(queries, queries+q);
while (true)
{
tie(shuffle, card, index)=queries[t];
while (shuffle==shuffles)
{
answer[index]=a[card-1];
t=t+1;
if (t==q)
break;
tie(shuffle, card, index)=queries[t];
}
if (t==q)
break;
for (i=n/2-1; i>=0; i--)
left.push_back(a[i]);
for (i=n-1; i>=n/2; i--)
right.push_back(a[i]);
if (right[n/2-1]>*max_element(left.begin(), left.end()))
break;
i=0;
while (!left.empty() && !right.empty())
{
if (left.back()<right.back())
{
a[i]=left.back();
left.pop_back();
i=i+1;
}
else
{
a[i]=right.back();
right.pop_back();
i=i+1;
}
}
while (!left.empty())
{
a[i]=left.back();
left.pop_back();
i=i+1;
}
while (!right.empty())
{
a[i]=right.back();
right.pop_back();
i=i+1;
}
shuffles=shuffles+1;
}
while (t<q)
{
tie(shuffle, card, index)=queries[t];
answer[index]=a[card-1];
t=t+1;
}
for (i=0; i<q; i++)
cout << answer[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1675 ms |
20340 KB |
Output is correct |
2 |
Correct |
1642 ms |
22480 KB |
Output is correct |
3 |
Correct |
1567 ms |
22540 KB |
Output is correct |
4 |
Correct |
1600 ms |
25060 KB |
Output is correct |
5 |
Correct |
1605 ms |
25424 KB |
Output is correct |
6 |
Correct |
1523 ms |
24172 KB |
Output is correct |
7 |
Correct |
1618 ms |
24072 KB |
Output is correct |
8 |
Correct |
1527 ms |
23496 KB |
Output is correct |
9 |
Correct |
1525 ms |
24052 KB |
Output is correct |
10 |
Correct |
1561 ms |
23556 KB |
Output is correct |
11 |
Correct |
1536 ms |
23756 KB |
Output is correct |
12 |
Correct |
1517 ms |
22568 KB |
Output is correct |
13 |
Correct |
1550 ms |
23160 KB |
Output is correct |
14 |
Correct |
1565 ms |
25780 KB |
Output is correct |
15 |
Correct |
1595 ms |
25908 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1534 ms |
24552 KB |
Output is correct |
18 |
Correct |
1515 ms |
24340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3070 ms |
31556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
4552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1675 ms |
20340 KB |
Output is correct |
2 |
Correct |
1642 ms |
22480 KB |
Output is correct |
3 |
Correct |
1567 ms |
22540 KB |
Output is correct |
4 |
Correct |
1600 ms |
25060 KB |
Output is correct |
5 |
Correct |
1605 ms |
25424 KB |
Output is correct |
6 |
Correct |
1523 ms |
24172 KB |
Output is correct |
7 |
Correct |
1618 ms |
24072 KB |
Output is correct |
8 |
Correct |
1527 ms |
23496 KB |
Output is correct |
9 |
Correct |
1525 ms |
24052 KB |
Output is correct |
10 |
Correct |
1561 ms |
23556 KB |
Output is correct |
11 |
Correct |
1536 ms |
23756 KB |
Output is correct |
12 |
Correct |
1517 ms |
22568 KB |
Output is correct |
13 |
Correct |
1550 ms |
23160 KB |
Output is correct |
14 |
Correct |
1565 ms |
25780 KB |
Output is correct |
15 |
Correct |
1595 ms |
25908 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1534 ms |
24552 KB |
Output is correct |
18 |
Correct |
1515 ms |
24340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Execution timed out |
3070 ms |
31556 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |