#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define mk make_pair
#define sz size()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x << endl, void();
#define int ll
#define pii pair <int, int>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("avx2")
const int N = 2e5 + 5, M = 1e3 + 5;
const int MOD = 998244353, INF = 2e9, sq = 300;
int a[M][N];
int n;
void merge (int x)
{
int l = 0, l2 = n / 2, l3 = 0;
while (l < n / 2 && l2 < n)
{
if (a[x - 1][l] < a[x - 1][l2])
a[x][l3++] = a[x - 1][l++];
else
a[x][l3++] = a[x - 1][l2++];
}
while (l < n / 2)
a[x][l3++] = a[x - 1][l++];
while (l2 < n)
a[x][l3++] = a[x - 1][l2++];
}
void Solve ()
{
int q, t, x;
cin >> n >> q;
if (n > 1000)
return;
for (int i = 0; i < n; i++)
cin >> a[0][i];
for (int i = 1; i < M; i++)
merge (i);
for (int i = 0; i < q; i++)
{
cin >> t >> x;
cout << a[min (t, M - 1)][x - 1] << endl;
}
}
int32_t main ()
{
ios::sync_with_stdio (0), cin.tie (0), cout.tie (0);
int tt = 1;
// cin >> tt;
while (tt--)
Solve ();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
19136 KB |
Output is correct |
2 |
Correct |
203 ms |
24548 KB |
Output is correct |
3 |
Correct |
216 ms |
23804 KB |
Output is correct |
4 |
Correct |
175 ms |
24936 KB |
Output is correct |
5 |
Correct |
186 ms |
24960 KB |
Output is correct |
6 |
Correct |
179 ms |
24356 KB |
Output is correct |
7 |
Correct |
202 ms |
24320 KB |
Output is correct |
8 |
Correct |
174 ms |
23656 KB |
Output is correct |
9 |
Correct |
175 ms |
24300 KB |
Output is correct |
10 |
Correct |
179 ms |
24020 KB |
Output is correct |
11 |
Correct |
179 ms |
23980 KB |
Output is correct |
12 |
Correct |
162 ms |
23280 KB |
Output is correct |
13 |
Correct |
179 ms |
23220 KB |
Output is correct |
14 |
Correct |
187 ms |
25428 KB |
Output is correct |
15 |
Correct |
183 ms |
25164 KB |
Output is correct |
16 |
Correct |
8 ms |
15180 KB |
Output is correct |
17 |
Correct |
164 ms |
24072 KB |
Output is correct |
18 |
Correct |
171 ms |
23992 KB |
Output is correct |
19 |
Correct |
3 ms |
7380 KB |
Output is correct |
20 |
Correct |
3 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
19136 KB |
Output is correct |
2 |
Correct |
203 ms |
24548 KB |
Output is correct |
3 |
Correct |
216 ms |
23804 KB |
Output is correct |
4 |
Correct |
175 ms |
24936 KB |
Output is correct |
5 |
Correct |
186 ms |
24960 KB |
Output is correct |
6 |
Correct |
179 ms |
24356 KB |
Output is correct |
7 |
Correct |
202 ms |
24320 KB |
Output is correct |
8 |
Correct |
174 ms |
23656 KB |
Output is correct |
9 |
Correct |
175 ms |
24300 KB |
Output is correct |
10 |
Correct |
179 ms |
24020 KB |
Output is correct |
11 |
Correct |
179 ms |
23980 KB |
Output is correct |
12 |
Correct |
162 ms |
23280 KB |
Output is correct |
13 |
Correct |
179 ms |
23220 KB |
Output is correct |
14 |
Correct |
187 ms |
25428 KB |
Output is correct |
15 |
Correct |
183 ms |
25164 KB |
Output is correct |
16 |
Correct |
8 ms |
15180 KB |
Output is correct |
17 |
Correct |
164 ms |
24072 KB |
Output is correct |
18 |
Correct |
171 ms |
23992 KB |
Output is correct |
19 |
Correct |
3 ms |
7380 KB |
Output is correct |
20 |
Correct |
3 ms |
7380 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |