Submission #1047127

#TimeUsernameProblemLanguageResultExecution timeMemory
1047127CirclingIndex (COCI21_index)C++17
0 / 110
3 ms604 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n, q, a, b, minans, maxans, midans; vector<vector<int>> tree; void addtotree(int x, int val, int node, int nodel, int noder){ if (x < nodel || noder <= x) return; if (nodel <= x && x < noder) tree[node].push_back(val); if (noder - nodel == 1) return; addtotree(x, val, 2 * node + 1, nodel, (nodel + noder) / 2); addtotree(x, val, 2 * node + 2, (nodel + noder) / 2, noder); } int greatercount(int l, int r, int val, int node, int nodel, int noder){ if (r <= nodel || noder <= l || tree[node][tree[node].size() - 1] < val) return 0; if (l <= nodel && noder <= r){ int mini = 0, maxi = noder - nodel - 1, midi; while (mini != maxi){ midi = (mini + maxi) / 2; if (val <= tree[node][midi]) maxi = midi; else mini = midi + 1; } return noder - nodel - midi; } return greatercount(l, r, val, 2 * node + 1, nodel, (nodel + noder) / 2) + greatercount(l, r, val, 2 * node + 2, (nodel + noder) / 2, noder); } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> q; tree.resize(4 * n); for (int i = 0; i < n; i++){ cin >> a; addtotree(i, a, 0, 0, n); } for (int i = 0; i < 4 * n; i++) sort(tree[i].begin(), tree[i].end()); while (q--){ cin >> a >> b; minans = 1; maxans = n; while (minans != maxans){ midans = (minans + maxans + 1) / 2; if (midans <= greatercount(a - 1, b, midans, 0, 0, n)) minans = midans; else maxans = midans - 1; } cout << minans << '\n'; } }

Compilation message (stderr)

index.cpp: In function 'int greatercount(int, int, int, int, int, int)':
index.cpp:29:32: warning: 'midi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |         return noder - nodel - midi;
      |                                ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...