#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
typedef long long llong;
const int MAXQ = 1000000 + 10;
const int MAXN = 200000 + 10;
const int INF = 1e9 + 1;
struct Query
{
int idx;
int pos;
int time;
inline friend bool operator < (const Query &a, const Query &b)
{
return a.time < b.time || (a.time == b.time && a.idx < b.idx);
}
};
int n, q;
int a[MAXN];
int b[MAXN];
Query queries[MAXQ];
int ans[MAXQ];
void solve()
{
int qPtr = 1;
bool areEqual = false;
std::sort(queries + 1, queries + 1 + q);
for (int shuffle = 0; !areEqual ; ++shuffle)
{
while (qPtr <= n && queries[qPtr].time == shuffle)
{
ans[queries[qPtr].idx] = a[queries[qPtr].pos];
qPtr++;
}
int lPtr = 1, rPtr = n/2 + 1, ptr = 1;
while (lPtr <= n/2 || rPtr <= n)
{
if (lPtr == n/2 + 1)
{
b[ptr++] = a[rPtr++];
continue;
}
if (rPtr == n + 1)
{
b[ptr++] = a[lPtr++];
continue;
}
if (a[lPtr] < a[rPtr])
{
b[ptr++] = a[lPtr++];
continue;
} else
{
b[ptr++] = a[rPtr++];
continue;
}
}
areEqual = true;
for (int i = 1 ; i <= n ; ++i)
{
areEqual &= (a[i] == b[i]);
a[i] = b[i];
}
}
while (qPtr <= n)
{
ans[queries[qPtr].idx] = a[queries[qPtr].pos];
qPtr++;
}
for (int i = 1 ; i <= q ; ++i)
{
std::cout << ans[i] << '\n';
}
}
void read()
{
std::cin >> n >> q;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
for (int i = 1 ; i <= q ; ++i)
{
std::cin >> queries[i].time >> queries[i].pos;
queries[i].idx = i;
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
278 ms |
16488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
13492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
2664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
278 ms |
16488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |