Submission #1055382

#TimeUsernameProblemLanguageResultExecution timeMemory
1055382fryingducIndex (COCI21_index)C++17
110 / 110
672 ms151700 KiB
/** * author: fryingduc * created:03.09.2023 20:39:40 **/ #include "bits/stdc++.h" using namespace std; #ifdef duc_debug #include "bits/debug.h" #else #define debug(...) #endif /* #define int long long */ const int maxn = 2e5+5; const int off = (1 << 18); struct Node{ int x; Node *l, *r; Node (int _x = 0, Node *_l = 0, Node *_r = 0){ x = _x; l = _l; r = _r; } }; Node* liu(){ Node *x = new Node(); x->r = x->l = x; return x; } Node *tmp; Node *tree[maxn]; Node *update(Node *ind, int l, int r, int x){ if(x < l || x > r) return ind; if(l == r){ return new Node(ind->x + 1, liu(), liu()); } int mid = (l + r) / 2; Node *left = update(ind->l, l, mid, x); Node *right = update(ind->r, mid + 1, r, x); return new Node(left->x + right->x, left, right); } int get(Node *ind, Node *prev, int l, int r, int x){ if(x > r || l >= maxn) return 0; if(l >= x) return ind->x - prev->x; int mid = (l + r) / 2; return get(ind->l, prev->l, l, mid, x) + get(ind->r, prev->r, mid + 1, r, x); } int get(Node *ind, Node *prev, int x){ return get(ind, prev, 1, off, x); } int n, q, a[maxn]; void solve(){ cin >> n >> q; for(int i = 1; i <= n; ++i){ cin >> a[i]; tmp = liu(); if(i > 1) tmp = tree[i - 1]; tree[i] = update(tmp, 1, off, a[i]); } while(q--){ int el, er; cin >> el >> er; int l = 0, r = maxn, res = 0; tmp = liu(); if(el > 1) tmp = tree[el - 1]; while(l <= r){ int mid = (l + r) / 2; if(get(tree[er], tmp, mid) >= mid){ l = mid + 1; res = mid; } else r = mid - 1; } cout << res << '\n'; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int test = 1; /* cin >> test; */ for(int i = 1; i <= test; i++){ /* cout << "Case " << "#" << i << ": "; */ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...