#include "bubblesort2.h"
#include <bits/stdc++.h>
constexpr int inf = 1 << 30;
class SegTree {
int n, size;
std::vector<int> data;
public:
SegTree() {}
SegTree(const std::vector<int> &vec) {
n = (int)vec.size();
size = 1;
while (size < n) size *= 2;
data.assign(2 * size, 0);
std::copy(vec.begin(), vec.end(), data.begin() + size);
for (int i = size - 1; i >= 1; --i) data[i] = data[2 * i] + data[2 * i + 1];
}
void set(int i, int v) {
i += size;
data[i] = v;
while (i != 1) {
i /= 2;
data[i] = data[2 * i] + data[2 * i + 1];
}
}
int fold(int l, int r) {
int ret = 0;
for (l += size, r += size; l < r; l /= 2, r /= 2) {
if (l & 1) ret += data[l++];
if (r & 1) ret += data[--r];
}
return ret;
}
};
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V) {
const int N = (int)A.size(), Q = (int)X.size();
{
std::vector<int> vals;
std::copy(A.begin(), A.end(), std::back_inserter(vals));
std::copy(V.begin(), V.end(), std::back_inserter(vals));
std::sort(vals.begin(), vals.end());
vals.erase(std::unique(vals.begin(), vals.end()), vals.end());
for (auto &e : A) e = (int)(std::lower_bound(vals.begin(), vals.end(), e) - vals.begin());
for (auto &e : V) e = (int)(std::lower_bound(vals.begin(), vals.end(), e) - vals.begin());
}
// subtask 3
const int M =
std::max(*std::max_element(A.begin(), A.end()), *std::max_element(V.begin(), V.end())) + 1;
assert(M <= 100);
std::vector<SegTree> seg(M + 1);
std::vector<std::set<int>> ids(M);
for (int x = 0; x <= M; ++x) {
std::vector<int> vec(N);
for (int i = 0; i < N; ++i) {
if (A[i] < x) {
vec[i] = 1;
}
if (A[i] == x) {
ids[x].insert(i);
}
}
seg[x] = SegTree(vec);
}
std::vector<int> answer(Q);
for (int q = 0; q < Q; ++q) {
const int x = X[q], newVal = V[q];
const int preVal = A[x];
ids[preVal].erase(x);
ids[newVal].insert(x);
for (int v = preVal + 1; v <= M; ++v) {
seg[v].set(x, 0);
}
for (int v = newVal + 1; v <= M; ++v) {
seg[v].set(x, 1);
}
A[x] = newVal;
for (int v = 0; v < M; ++v) {
if (ids[v].empty()) continue;
const int i = *ids[v].rbegin();
answer[q] = std::max(answer[q], i - seg[v + 1].fold(0, i));
}
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
28236 KB |
Output is correct |
2 |
Correct |
569 ms |
55568 KB |
Output is correct |
3 |
Correct |
1035 ms |
56460 KB |
Output is correct |
4 |
Correct |
1033 ms |
56424 KB |
Output is correct |
5 |
Correct |
814 ms |
56416 KB |
Output is correct |
6 |
Correct |
853 ms |
56436 KB |
Output is correct |
7 |
Correct |
655 ms |
56412 KB |
Output is correct |
8 |
Correct |
673 ms |
56428 KB |
Output is correct |
9 |
Correct |
597 ms |
56424 KB |
Output is correct |
10 |
Correct |
553 ms |
56500 KB |
Output is correct |
11 |
Correct |
557 ms |
56492 KB |
Output is correct |
12 |
Correct |
549 ms |
56496 KB |
Output is correct |
13 |
Correct |
615 ms |
56592 KB |
Output is correct |
14 |
Correct |
618 ms |
56492 KB |
Output is correct |
15 |
Correct |
610 ms |
56408 KB |
Output is correct |
16 |
Correct |
651 ms |
56632 KB |
Output is correct |
17 |
Correct |
647 ms |
56560 KB |
Output is correct |
18 |
Correct |
640 ms |
56508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |