# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
494337 |
2021-12-15T07:47:25 Z |
AlperenT |
Index (COCI21_index) |
C++17 |
|
2500 ms |
47620 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q, arr[N], a, b, l, r, m;
struct SegTree{
vector<int> tree[N * 4];
void build(int v = 1, int l = 1, int r = n){
if(l == r) tree[v].push_back(arr[l]);
else{
int m = l + (r - l) / 2;
build(v * 2, l, m); build(v * 2 + 1, m + 1, r);
tree[v].assign(tree[v * 2].size() + tree[v * 2 + 1].size(), 0);
merge(tree[v * 2].begin(), tree[v * 2].end(), tree[v * 2 + 1].begin(), tree[v * 2 + 1].end(), tree[v].begin());
}
}
int query(int l, int r, int val, int v = 1, int tl = 1, int tr = n){
if(l > r) return 0;
else if(tl == l && tr == r) return tree[v].end() - lower_bound(tree[v].begin(), tree[v].end(), val);
else{
int tm = tl + (tr - tl) / 2;
return query(l, min(tm, r), val, v * 2, tl, tm) + query(max(tm + 1, l), r, val, v * 2 + 1, tm + 1, tr);
}
}
};
SegTree sgt;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> arr[i];
sgt.build();
while(q--){
cin >> a >> b;
l = 1, r = (b - a + 1) + 1;
while(r - l > 1){
m = l + (r - l) / 2;
if(sgt.query(a, b, m) >= m) l = m;
else r = m;
}
cout << l << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19148 KB |
Output is correct |
2 |
Correct |
13 ms |
19148 KB |
Output is correct |
3 |
Correct |
13 ms |
19108 KB |
Output is correct |
4 |
Correct |
13 ms |
19148 KB |
Output is correct |
5 |
Correct |
14 ms |
19148 KB |
Output is correct |
6 |
Correct |
13 ms |
19124 KB |
Output is correct |
7 |
Correct |
14 ms |
19196 KB |
Output is correct |
8 |
Correct |
13 ms |
19108 KB |
Output is correct |
9 |
Correct |
14 ms |
19148 KB |
Output is correct |
10 |
Correct |
13 ms |
19180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19148 KB |
Output is correct |
2 |
Correct |
13 ms |
19148 KB |
Output is correct |
3 |
Correct |
13 ms |
19108 KB |
Output is correct |
4 |
Correct |
13 ms |
19148 KB |
Output is correct |
5 |
Correct |
14 ms |
19148 KB |
Output is correct |
6 |
Correct |
13 ms |
19124 KB |
Output is correct |
7 |
Correct |
14 ms |
19196 KB |
Output is correct |
8 |
Correct |
13 ms |
19108 KB |
Output is correct |
9 |
Correct |
14 ms |
19148 KB |
Output is correct |
10 |
Correct |
13 ms |
19180 KB |
Output is correct |
11 |
Correct |
668 ms |
26000 KB |
Output is correct |
12 |
Correct |
661 ms |
25840 KB |
Output is correct |
13 |
Correct |
683 ms |
25864 KB |
Output is correct |
14 |
Correct |
668 ms |
25896 KB |
Output is correct |
15 |
Correct |
697 ms |
25956 KB |
Output is correct |
16 |
Correct |
683 ms |
26052 KB |
Output is correct |
17 |
Correct |
668 ms |
26136 KB |
Output is correct |
18 |
Correct |
664 ms |
25916 KB |
Output is correct |
19 |
Correct |
677 ms |
25916 KB |
Output is correct |
20 |
Correct |
674 ms |
26108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19148 KB |
Output is correct |
2 |
Correct |
13 ms |
19148 KB |
Output is correct |
3 |
Correct |
13 ms |
19108 KB |
Output is correct |
4 |
Correct |
13 ms |
19148 KB |
Output is correct |
5 |
Correct |
14 ms |
19148 KB |
Output is correct |
6 |
Correct |
13 ms |
19124 KB |
Output is correct |
7 |
Correct |
14 ms |
19196 KB |
Output is correct |
8 |
Correct |
13 ms |
19108 KB |
Output is correct |
9 |
Correct |
14 ms |
19148 KB |
Output is correct |
10 |
Correct |
13 ms |
19180 KB |
Output is correct |
11 |
Correct |
668 ms |
26000 KB |
Output is correct |
12 |
Correct |
661 ms |
25840 KB |
Output is correct |
13 |
Correct |
683 ms |
25864 KB |
Output is correct |
14 |
Correct |
668 ms |
25896 KB |
Output is correct |
15 |
Correct |
697 ms |
25956 KB |
Output is correct |
16 |
Correct |
683 ms |
26052 KB |
Output is correct |
17 |
Correct |
668 ms |
26136 KB |
Output is correct |
18 |
Correct |
664 ms |
25916 KB |
Output is correct |
19 |
Correct |
677 ms |
25916 KB |
Output is correct |
20 |
Correct |
674 ms |
26108 KB |
Output is correct |
21 |
Execution timed out |
2583 ms |
47620 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |