# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1047130 |
2024-08-07T09:10:59 Z |
vjudge1 |
Index (COCI21_index) |
C++17 |
|
2356 ms |
47224 KB |
#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 - mini;
}
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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
380 ms |
11728 KB |
Output is correct |
12 |
Correct |
375 ms |
11680 KB |
Output is correct |
13 |
Correct |
401 ms |
11740 KB |
Output is correct |
14 |
Correct |
368 ms |
11724 KB |
Output is correct |
15 |
Correct |
406 ms |
11724 KB |
Output is correct |
16 |
Correct |
372 ms |
11688 KB |
Output is correct |
17 |
Correct |
424 ms |
11728 KB |
Output is correct |
18 |
Correct |
377 ms |
11728 KB |
Output is correct |
19 |
Correct |
372 ms |
11728 KB |
Output is correct |
20 |
Correct |
389 ms |
11664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
380 ms |
11728 KB |
Output is correct |
12 |
Correct |
375 ms |
11680 KB |
Output is correct |
13 |
Correct |
401 ms |
11740 KB |
Output is correct |
14 |
Correct |
368 ms |
11724 KB |
Output is correct |
15 |
Correct |
406 ms |
11724 KB |
Output is correct |
16 |
Correct |
372 ms |
11688 KB |
Output is correct |
17 |
Correct |
424 ms |
11728 KB |
Output is correct |
18 |
Correct |
377 ms |
11728 KB |
Output is correct |
19 |
Correct |
372 ms |
11728 KB |
Output is correct |
20 |
Correct |
389 ms |
11664 KB |
Output is correct |
21 |
Correct |
2295 ms |
47224 KB |
Output is correct |
22 |
Correct |
2278 ms |
47020 KB |
Output is correct |
23 |
Correct |
2276 ms |
47212 KB |
Output is correct |
24 |
Correct |
2278 ms |
47148 KB |
Output is correct |
25 |
Correct |
2356 ms |
47020 KB |
Output is correct |
26 |
Correct |
2275 ms |
47204 KB |
Output is correct |
27 |
Correct |
2234 ms |
47032 KB |
Output is correct |
28 |
Correct |
2202 ms |
47016 KB |
Output is correct |
29 |
Correct |
2192 ms |
47092 KB |
Output is correct |
30 |
Correct |
2255 ms |
47056 KB |
Output is correct |