Submission #662105

#TimeUsernameProblemLanguageResultExecution timeMemory
662105Sohsoh84Abracadabra (CEOI22_abracadabra)C++17
10 / 100
1982 ms524288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e3 + 10; vector<int> tmerge(vector<int> a, vector<int> b) { int pa = 0, pb = 0; vector<int> ans; while (pa < int(a.size()) || pb < int(b.size())) { if (pa == int(a.size()) || (pb < int(b.size()) && b[pb] < a[pa])) ans.push_back(b[pb++]); else ans.push_back(a[pa++]); } return ans; } int n, q; vector<int> vec[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) { int x; cin >> x; vec[0].push_back(x); } for (int i = 1; i < MAXN; i++) { vector<int> A[2]; for (int j = 0; j < n; j++) A[j >= n / 2].push_back(vec[i - 1][j]); vec[i] = tmerge(A[0], A[1]); } while (q--) { int a, b; cin >> a >> b; a = min(1ll * a, MAXN - 1); cout << vec[a][b - 1] << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...