Submission #1053212

#TimeUsernameProblemLanguageResultExecution timeMemory
1053212vjudge1Abracadabra (CEOI22_abracadabra)C++17
10 / 100
3083 ms40416 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << endl; void g(vector<int>&a) { for (auto el : a) cout << el << ", "; cout << endl; } void solve() { int n,q;cin>>n>>q; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<tuple<int, int, int>> queries(q); for (int i = 0; i < q; i++) { int t,j;cin>>t>>j;j--; queries[i] = {t,j,i}; } sort(all(queries)); vector<int> ans(q); function<void()> shuffle = [&]() { vector<int> left, right; for (int i = 0; i < n; i++) { if (i < n/2) left.push_back(a[i]); else right.push_back(a[i]); } left.push_back(1e18); right.push_back(1e18); reverse(all(left)); reverse(all(right)); vector<int> cur; for (int i = 0; i < n; i++) { if (left.back() < right.back()) { cur.push_back(left.back()); left.pop_back(); } else { cur.push_back(right.back()); right.pop_back(); } } a = cur; }; int nowt = 0; bool ok = 0; for (int i = 0; i < q; i++) { auto [t, idx, cid] = queries[i]; while (nowt != t && !ok) { vector<int> prev = a; shuffle(); if (prev == a) ok = 1; // g(a); nowt++; } // g(a); ans[cid] = a[idx]; } for (auto el : ans) cout << el << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0); int t=1; while(t--) solve(); 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...