Submission #1011204

#TimeUsernameProblemLanguageResultExecution timeMemory
1011204ForestedAbracadabra (CEOI22_abracadabra)C++17
10 / 100
3050 ms32700 KiB
#include <bits/stdc++.h> using namespace std; using i32 = int; using i64 = long long; template <typename T> using V = vector<T>; template <typename T> using VV = V<V<T>>; #define OVERRIDE4(a, b, c, d, ...) d #define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i) #define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i) #define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) #define PER2(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i) #define PER3(i, l, r) for (i32 i = (i32)(r) - 1; i >= (i32)(l); --i) #define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__) #define LEN(x) (i32)size(x) #define ALL(x) begin(x), end(x) template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } V<i32> riffle(V<i32> a) { V<i32> b; b.reserve(LEN(a)); i32 l = 0, r = LEN(a) / 2; i32 lto = r, rto = LEN(a); while (LEN(b) < LEN(a)) { if (r == rto || (l < lto && a[l] < a[r])) { b.push_back(a[l++]); } else { b.push_back(a[r++]); } } return b; } int main() { i32 n, q; cin >> n >> q; V<i32> a(n); REP(i, n) { cin >> a[i]; } V<i32> t(q), idx(q); REP(i, q) { cin >> t[i] >> idx[i]; --idx[i]; } map<i32, V<i32>> mt; REP(i, q) { mt[t[i]].push_back(i); } V<i32> ans(q, -1); i32 x = 0; while (true) { if (mt.count(x)) { for (i32 i : mt[x]) { ans[i] = a[idx[i]]; } } V<i32> b = riffle(a); if (a == b) { break; } a = b; ++x; } REP(i, q) { if (ans[i] == -1) { ans[i] = a[idx[i]]; } } REP(i, q) { cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...