// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<int> a;
bool f1 = 0;
void move() {
if(f1) return;
vector<int> tmp(1, 0);
int i = 1, j = n / 2 + 1;
while(i <= n / 2 && j <= n) {
if(a[i] < a[j]) {
tmp.pb(a[i]);
i++;
}
else {
tmp.pb(a[j]);
j++;
}
}
while(i <= n / 2) {
tmp.pb(a[i]);
i++;
}
while(j <= n) {
tmp.pb(a[j]);
j++;
}
if(tmp == a) f1 = 1;;
a = tmp;
return;
}
inline void solve() {
cin>>n>>q;
a.resize(n + 1);
for(int i = 1; i<=n; i++) cin >> a[i];
vector<array<int,3> > qu;
qu.resize(q);
REP(i, q) {
cin >> qu[i][0] >> qu[i][1];
qu[i][2] = i;
}
sort(all(qu));
vector<int> res(q);
int t = 0;
for(auto &c : qu) {
while(t < c[0]) {
if(f1) {
t = c[0];
break;
}
move();
t++;
}
res[c[2]] = a[c[1]];
}
REP(i, q) cout << res[i] << "\n";
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
27472 KB |
Output is correct |
2 |
Correct |
295 ms |
27232 KB |
Output is correct |
3 |
Correct |
301 ms |
26452 KB |
Output is correct |
4 |
Correct |
322 ms |
25196 KB |
Output is correct |
5 |
Correct |
291 ms |
26944 KB |
Output is correct |
6 |
Correct |
285 ms |
25336 KB |
Output is correct |
7 |
Correct |
306 ms |
27080 KB |
Output is correct |
8 |
Correct |
289 ms |
25680 KB |
Output is correct |
9 |
Correct |
313 ms |
25220 KB |
Output is correct |
10 |
Correct |
298 ms |
25624 KB |
Output is correct |
11 |
Correct |
292 ms |
25592 KB |
Output is correct |
12 |
Correct |
315 ms |
24560 KB |
Output is correct |
13 |
Correct |
292 ms |
25428 KB |
Output is correct |
14 |
Correct |
323 ms |
26168 KB |
Output is correct |
15 |
Correct |
343 ms |
26096 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
276 ms |
24872 KB |
Output is correct |
18 |
Correct |
300 ms |
24772 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3047 ms |
33596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3010 ms |
5548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
27472 KB |
Output is correct |
2 |
Correct |
295 ms |
27232 KB |
Output is correct |
3 |
Correct |
301 ms |
26452 KB |
Output is correct |
4 |
Correct |
322 ms |
25196 KB |
Output is correct |
5 |
Correct |
291 ms |
26944 KB |
Output is correct |
6 |
Correct |
285 ms |
25336 KB |
Output is correct |
7 |
Correct |
306 ms |
27080 KB |
Output is correct |
8 |
Correct |
289 ms |
25680 KB |
Output is correct |
9 |
Correct |
313 ms |
25220 KB |
Output is correct |
10 |
Correct |
298 ms |
25624 KB |
Output is correct |
11 |
Correct |
292 ms |
25592 KB |
Output is correct |
12 |
Correct |
315 ms |
24560 KB |
Output is correct |
13 |
Correct |
292 ms |
25428 KB |
Output is correct |
14 |
Correct |
323 ms |
26168 KB |
Output is correct |
15 |
Correct |
343 ms |
26096 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
276 ms |
24872 KB |
Output is correct |
18 |
Correct |
300 ms |
24772 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3047 ms |
33596 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |