#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<int,int> pii;
using namespace std;
vector<int> shf(vector<int> vec)
{
int n = vec.size();
vector<int> ans;
int p0 = 0, p1 = n/2;
Loop (_,0,n) {
if (p1 == n || (p0 < n/2 && vec[p0] < vec[p1]))
ans.push_back(vec[p0++]);
else
ans.push_back(vec[p1++]);
}
return ans;
}
const int N = 1'000'010;
int ans[N];
vector<pii> Q[N];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<int> vec(n);
//iota(vec.begin(), vec.end(), 0);
//auto pleh = vec;
//int cntt = 0;
//for (;;) {
// int cnt = 0;
// vec = pleh;
// for (;;) {
// auto tmp = shf(vec);
// if (tmp == vec)
// break;
// vec = tmp;
// ++cnt;
// }
// cntt = max(cntt, cnt);
// if (!next_permutation(pleh.begin(), pleh.end()))
// break;
//}
//cout << cntt << '\n';
//return 0;
//mt19937_64 rd(chrono::high_resolution_clock::now().time_since_epoch().count());
//iota(vec.begin(), vec.end(), 0);
//shuffle(vec.begin(), vec.end(), rd);
for (int &x : vec)
cin >> x;
//vecs.push_back(vec);
Loop (i,0,q) {
int t, p;
cin >> t >> p;
--p;
t = min(t, n);
Q[t].push_back({p, i});
}
Loop (i,0,n) {
for (auto [p, j] : Q[i])
ans[j] = vec[p];
inplace_merge(vec.data(), vec.data()+n/2, vec.data()+n);//vec = shf(vec);
//vec = shf(vec);
}
for (auto [p, j] : Q[n])
ans[j] = vec[p];
Loop (i,0,q)
cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
41960 KB |
Output is correct |
2 |
Correct |
183 ms |
40848 KB |
Output is correct |
3 |
Correct |
177 ms |
40348 KB |
Output is correct |
4 |
Correct |
185 ms |
40180 KB |
Output is correct |
5 |
Correct |
173 ms |
42824 KB |
Output is correct |
6 |
Correct |
167 ms |
42808 KB |
Output is correct |
7 |
Correct |
183 ms |
43080 KB |
Output is correct |
8 |
Correct |
159 ms |
41620 KB |
Output is correct |
9 |
Correct |
158 ms |
40552 KB |
Output is correct |
10 |
Correct |
154 ms |
40248 KB |
Output is correct |
11 |
Correct |
163 ms |
40776 KB |
Output is correct |
12 |
Correct |
153 ms |
38976 KB |
Output is correct |
13 |
Correct |
161 ms |
39792 KB |
Output is correct |
14 |
Correct |
160 ms |
41872 KB |
Output is correct |
15 |
Correct |
174 ms |
40212 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
159 ms |
39160 KB |
Output is correct |
18 |
Correct |
157 ms |
38980 KB |
Output is correct |
19 |
Correct |
13 ms |
23716 KB |
Output is correct |
20 |
Correct |
15 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3058 ms |
33180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3020 ms |
27016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
41960 KB |
Output is correct |
2 |
Correct |
183 ms |
40848 KB |
Output is correct |
3 |
Correct |
177 ms |
40348 KB |
Output is correct |
4 |
Correct |
185 ms |
40180 KB |
Output is correct |
5 |
Correct |
173 ms |
42824 KB |
Output is correct |
6 |
Correct |
167 ms |
42808 KB |
Output is correct |
7 |
Correct |
183 ms |
43080 KB |
Output is correct |
8 |
Correct |
159 ms |
41620 KB |
Output is correct |
9 |
Correct |
158 ms |
40552 KB |
Output is correct |
10 |
Correct |
154 ms |
40248 KB |
Output is correct |
11 |
Correct |
163 ms |
40776 KB |
Output is correct |
12 |
Correct |
153 ms |
38976 KB |
Output is correct |
13 |
Correct |
161 ms |
39792 KB |
Output is correct |
14 |
Correct |
160 ms |
41872 KB |
Output is correct |
15 |
Correct |
174 ms |
40212 KB |
Output is correct |
16 |
Correct |
14 ms |
23764 KB |
Output is correct |
17 |
Correct |
159 ms |
39160 KB |
Output is correct |
18 |
Correct |
157 ms |
38980 KB |
Output is correct |
19 |
Correct |
13 ms |
23716 KB |
Output is correct |
20 |
Correct |
15 ms |
23764 KB |
Output is correct |
21 |
Execution timed out |
3058 ms |
33180 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |