제출 #1151442

#제출 시각아이디문제언어결과실행 시간메모리
1151442IssaAbracadabra (CEOI22_abracadabra)C++20
10 / 100
3095 ms20152 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 2e6 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e7 + 100; const ll MOD = 1e9 + 7; const int maxl = 16; const ll P = 31; int n, q; int a[maxn]; int b[maxn]; int ans[maxn]; bool sorted; void calc(){ for(int k = 1, i = 1, j = n / 2 + 1; k <= n; k++){ if(i <= n / 2 && (j > n || a[i] < a[j])) b[k] = a[i++]; else b[k] = a[j++]; } sorted = 1; for(int i = 1; i <= n; i++){ sorted &= a[i] == b[i]; a[i] = b[i]; } } void test(){ cin >> n >> q; for(int i = 1; i <= n; i++){ cin >> a[i]; } vector<pair<int, pii>> v; for(int i = 1; i <= q; i++){ int t, p; cin >> t >> p; v.push_back({t, {p, i}}); } v.push_back({0, {0, 0}}); sort(v.begin(), v.end()); for(int i = 1; i < v.size(); i++){ for(int cnt = 0; cnt < v[i].first - v[i-1].first; cnt++){ if(sorted) break; calc(); } auto [p, id] = v[i].second; ans[id] = a[p]; } for(int i = 1; i <= q; i++){ cout << ans[i] << ent; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while(t--) test(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...