Submission #798115

#TimeUsernameProblemLanguageResultExecution timeMemory
798115IvanJAbracadabra (CEOI22_abracadabra)C++17
10 / 100
3051 ms31348 KiB
#include<bits/stdc++.h> #define pb push_back #define x first #define y second #define all(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 2e5 + 5, maxq = 1e6 + 5; int n, q; int p[maxn]; int ans[maxq]; vector<ii> qs[maxn]; vector<int> get(vector<int> L, vector<int> R) { int i = 0, j = 0; vector<int> ret; while(i < (n / 2) || j < (n / 2)) { if(i == n / 2) ret.pb(R[j++]); else if(j == n / 2) ret.pb(L[i++]); else { if(L[i] < R[j]) ret.pb(L[i++]); else ret.pb(R[j++]); } } return ret; } int main() { scanf("%d%d", &n, &q); for(int i = 0;i < n;i++) scanf("%d", p + i); for(int i = 0;i < q;i++) { int t, x; scanf("%d%d", &t, &x); x--; qs[min(t, n)].pb({x, i}); } for(int t = 0;t <= n;t++) { for(ii qi : qs[t]) ans[qi.y] = p[qi.x]; vector<int> L, R; for(int i = 0;i < n / 2;i++) L.pb(p[i]); for(int i = n / 2;i < n;i++) R.pb(p[i]); vector<int> v = get(L, R); for(int i = 0;i < n;i++) p[i] = v[i]; } for(int i = 0;i < q;i++) printf("%d\n", ans[i]); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", p + i);
      |   ~~~~~^~~~~~~~~~~~~
Main.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &t, &x);
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...