# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
682619 |
2023-01-16T15:33:08 Z |
vjudge1 |
Index (COCI21_index) |
C++17 |
|
2500 ms |
31796 KB |
#include <bits/stdc++.h>
// Sample problem: https://oj.uz/problem/view/COCI21_index?locale=en
using namespace std;
const int N = 2e5;
const int INF = 1e9;
vector<pair<int, int>> aib[1 + N];
void build() {
for (int i = 1; i <= N; ++i) {
aib[i].emplace_back(0, 0);
}
}
void update(int version, int p, int v) {
for (int i = p; i <= N; i += i & -i) {
aib[i].emplace_back(version, aib[i].back().second + v);
}
}
int query(int version, int p) {
int res = 0;
for (int i = p; i > 0; i = i & (i - 1)) {
res += prev(upper_bound(aib[i].begin(), aib[i].end(), make_pair(version, INF)))->second;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
build();
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
update(i, x, 1);
}
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
int len = r - l + 1;
int st = 2, dr = len, res = 1;
while (st <= dr) {
int mid = (st + dr) / 2;
if (len - (query(r, mid - 1) - query(l - 1, mid - 1)) >= mid) {
res = mid;
st = mid + 1;
} else {
dr = mid - 1;
}
}
cout << res << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
11348 KB |
Output is correct |
2 |
Correct |
15 ms |
11348 KB |
Output is correct |
3 |
Correct |
16 ms |
11364 KB |
Output is correct |
4 |
Correct |
15 ms |
11288 KB |
Output is correct |
5 |
Correct |
16 ms |
11296 KB |
Output is correct |
6 |
Correct |
15 ms |
11412 KB |
Output is correct |
7 |
Correct |
16 ms |
11416 KB |
Output is correct |
8 |
Correct |
14 ms |
11324 KB |
Output is correct |
9 |
Correct |
14 ms |
11348 KB |
Output is correct |
10 |
Correct |
16 ms |
11424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
11348 KB |
Output is correct |
2 |
Correct |
15 ms |
11348 KB |
Output is correct |
3 |
Correct |
16 ms |
11364 KB |
Output is correct |
4 |
Correct |
15 ms |
11288 KB |
Output is correct |
5 |
Correct |
16 ms |
11296 KB |
Output is correct |
6 |
Correct |
15 ms |
11412 KB |
Output is correct |
7 |
Correct |
16 ms |
11416 KB |
Output is correct |
8 |
Correct |
14 ms |
11324 KB |
Output is correct |
9 |
Correct |
14 ms |
11348 KB |
Output is correct |
10 |
Correct |
16 ms |
11424 KB |
Output is correct |
11 |
Correct |
531 ms |
17060 KB |
Output is correct |
12 |
Correct |
505 ms |
16932 KB |
Output is correct |
13 |
Correct |
553 ms |
16800 KB |
Output is correct |
14 |
Correct |
546 ms |
16836 KB |
Output is correct |
15 |
Correct |
519 ms |
16948 KB |
Output is correct |
16 |
Correct |
555 ms |
16968 KB |
Output is correct |
17 |
Correct |
525 ms |
17036 KB |
Output is correct |
18 |
Correct |
556 ms |
16792 KB |
Output is correct |
19 |
Correct |
564 ms |
16740 KB |
Output is correct |
20 |
Correct |
529 ms |
16952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
11348 KB |
Output is correct |
2 |
Correct |
15 ms |
11348 KB |
Output is correct |
3 |
Correct |
16 ms |
11364 KB |
Output is correct |
4 |
Correct |
15 ms |
11288 KB |
Output is correct |
5 |
Correct |
16 ms |
11296 KB |
Output is correct |
6 |
Correct |
15 ms |
11412 KB |
Output is correct |
7 |
Correct |
16 ms |
11416 KB |
Output is correct |
8 |
Correct |
14 ms |
11324 KB |
Output is correct |
9 |
Correct |
14 ms |
11348 KB |
Output is correct |
10 |
Correct |
16 ms |
11424 KB |
Output is correct |
11 |
Correct |
531 ms |
17060 KB |
Output is correct |
12 |
Correct |
505 ms |
16932 KB |
Output is correct |
13 |
Correct |
553 ms |
16800 KB |
Output is correct |
14 |
Correct |
546 ms |
16836 KB |
Output is correct |
15 |
Correct |
519 ms |
16948 KB |
Output is correct |
16 |
Correct |
555 ms |
16968 KB |
Output is correct |
17 |
Correct |
525 ms |
17036 KB |
Output is correct |
18 |
Correct |
556 ms |
16792 KB |
Output is correct |
19 |
Correct |
564 ms |
16740 KB |
Output is correct |
20 |
Correct |
529 ms |
16952 KB |
Output is correct |
21 |
Execution timed out |
2598 ms |
31796 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |