# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1036825 | 2024-07-27T17:37:59 Z | vjudge1 | Abracadabra (CEOI22_abracadabra) | C++17 | 3000 ms | 39084 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sort undefined_function // To use stable_sort instead sort #define bpc __builtin_popcount #define ull unsigned long long #define ld double #define ll long long #define mp make_pair #define F first #define S second #pragma GCC optimize("O3") #ifdef LOCAL #include "debug.h" #else #define dbg(...) 0 #endif using namespace __gnu_pbds; using namespace std; typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> Tree; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll INF = 9223372036854775807LL; const ll inf = 2147483647; const ll MOD = 998244353; //[998244353, 1e9 + 7, 1e9 + 13] const ld PI = acos(-1); const ll NROOT = 800; ll binpow(ll a, ll b, ll _MOD = -1) { if (_MOD == -1) _MOD = MOD; ll res = 1; for (; b; b /= 2, a *= a, a %= _MOD) if (b & 1) res *= a, res %= _MOD; return res; } void set_IO(string s) { #ifndef LOCAL string in = s + ".in"; string out = s + ".out"; freopen(in.c_str(), "r", stdin); freopen(out.c_str(), "w", stdout); #endif } bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);} ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} ll lcm(ll a, ll b) {return a * b / gcd(a, b);} ll ceil(ll a, ll b) {return (a + b - 1) / b;} ll invmod(ll a) {return binpow(a, MOD - 2);} int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<int> v(n + 1); for (int i = 1; i <= n; i ++) cin >> v[i]; vector<pair<pair<int, int>, int>>qr(q + 1); for (int i = 1; i <= q; i ++) { cin >> qr[i].F.F >> qr[i].F.S; qr[i].S = i; } stable_sort(qr.begin() + 1, qr.end()); vector<int> ans(q + 1, -1); int iter = 1; vector<int> lst = {-1}; for (int i = 0; iter < qr.size(); i ++) { while (iter < qr.size() && qr[iter].F.F == i) { ans[qr[iter].S] = v[qr[iter].F.S]; iter ++; } vector<int> half1, half2, prv = v; for (int j = 1; j <= n / 2; j ++) half1.push_back(v[j]); for (int j = n / 2 + 1; j <= n; j ++) half2.push_back(v[j]); reverse(half1.begin(), half1.end()); reverse(half2.begin(), half2.end()); int tmp = 1; while (!half1.empty() && !half2.empty()) { if (half1.back() < half2.back()) { v[tmp] = half1.back(); half1.pop_back(); } else { v[tmp] = half2.back(); half2.pop_back(); } tmp ++; } while (!half1.empty()) { v[tmp] = half1.back(); half1.pop_back(); tmp ++; } while (!half2.empty()) { v[tmp] = half2.back(); half2.pop_back(); tmp ++; } if (v == lst) break; lst = prv; } for (int i = 1; i <= n; i ++) if (ans[qr[i].S] == -1) ans[qr[i].S] = v[qr[i].F.S]; for (int i = 1; i <= q; i ++) { cout << ans[i] << "\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 247 ms | 31380 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3069 ms | 39084 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3069 ms | 5564 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 247 ms | 31380 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |