#include <bits/stdc++.h>
#include "bubblesort2.h"
#define INF 0x3f3f3f3f
using namespace std;
struct ST {
int n;
vector<int> t, lazy;
ST(int N) : n(N) {
int dim = 1;
while (dim < n) {
dim *= 2;
}
dim *= 2;
t.resize(dim, -INF);
lazy.resize(dim);
}
void updateNode(int x, int v) {
t[x] += v;
lazy[x] += v;
}
void push(int x) {
if (lazy[x] == 0) {
return;
}
for (int i = 0; i < 2; ++i) {
updateNode(x * 2 + i, lazy[x]);
}
lazy[x] = 0;
}
void update(int x, int lx, int rx, int st, int dr, int v) {
if (st <= lx && rx <= dr) {
updateNode(x, v);
return;
}
push(x);
int mid = (lx + rx) / 2;
if (st <= mid) {
update(x * 2, lx, mid, st, dr, v);
}
if (mid < dr) {
update(x * 2 + 1, mid + 1, rx, st, dr, v);
}
t[x] = max(t[x * 2], t[x * 2 + 1]);
}
void update(int st, int dr, int v) {
if (dr < st) {
return;
}
update(1, 0, n - 1, st, dr, v);
}
int getMax() {
return t[1];
}
};
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
int n = a.size(), q = x.size();
vector<pair<int, int>> pairs;
pairs.reserve(n + q);
for (int i = 0; i < n; ++i) {
pairs.emplace_back(a[i], i);
}
for (int i = 0; i < q; ++i) {
pairs.emplace_back(v[i], x[i]);
}
sort(pairs.begin(), pairs.end());
map<pair<int, int>, int> order;
order[pairs[0]] = 0;
int N = 0;
for (int i = 1; i < (int)pairs.size(); ++i) {
if (pairs[i] != pairs[i - 1]) {
N += 1;
}
order[pairs[i]] = N;
}
N += 1;
ST t(N);
auto update = [&](const int &index, const int &pos, const int &sgn) -> void {
t.update(index, index, sgn * INF);
t.update(index, index, sgn * pos);
t.update(index + 1, N - 1, -sgn);
};
for (int i = 0; i < n; ++i) {
update(order[{a[i], i}], i, 1);
}
vector<int> sol(q);
for (int i = 0; i < q; ++i) {
update(order[{a[x[i]], x[i]}], x[i], -1);
a[x[i]] = v[i];
update(order[{a[x[i]], x[i]}], x[i], 1);
sol[i] = t.getMax();
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
5 ms |
716 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
6 ms |
696 KB |
Output is correct |
6 |
Correct |
5 ms |
704 KB |
Output is correct |
7 |
Correct |
5 ms |
688 KB |
Output is correct |
8 |
Correct |
6 ms |
696 KB |
Output is correct |
9 |
Correct |
5 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
684 KB |
Output is correct |
11 |
Correct |
5 ms |
684 KB |
Output is correct |
12 |
Correct |
5 ms |
688 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
5 ms |
588 KB |
Output is correct |
15 |
Correct |
5 ms |
688 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
5 ms |
716 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
6 ms |
696 KB |
Output is correct |
6 |
Correct |
5 ms |
704 KB |
Output is correct |
7 |
Correct |
5 ms |
688 KB |
Output is correct |
8 |
Correct |
6 ms |
696 KB |
Output is correct |
9 |
Correct |
5 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
684 KB |
Output is correct |
11 |
Correct |
5 ms |
684 KB |
Output is correct |
12 |
Correct |
5 ms |
688 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
5 ms |
588 KB |
Output is correct |
15 |
Correct |
5 ms |
688 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
21 ms |
1868 KB |
Output is correct |
20 |
Correct |
24 ms |
2064 KB |
Output is correct |
21 |
Correct |
23 ms |
1996 KB |
Output is correct |
22 |
Correct |
29 ms |
2188 KB |
Output is correct |
23 |
Correct |
22 ms |
1932 KB |
Output is correct |
24 |
Correct |
22 ms |
1840 KB |
Output is correct |
25 |
Correct |
21 ms |
1820 KB |
Output is correct |
26 |
Correct |
21 ms |
1832 KB |
Output is correct |
27 |
Correct |
20 ms |
1792 KB |
Output is correct |
28 |
Correct |
20 ms |
1684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3020 KB |
Output is correct |
2 |
Correct |
109 ms |
7076 KB |
Output is correct |
3 |
Correct |
216 ms |
11292 KB |
Output is correct |
4 |
Correct |
211 ms |
11248 KB |
Output is correct |
5 |
Correct |
212 ms |
11240 KB |
Output is correct |
6 |
Correct |
203 ms |
11076 KB |
Output is correct |
7 |
Correct |
194 ms |
11132 KB |
Output is correct |
8 |
Correct |
210 ms |
11232 KB |
Output is correct |
9 |
Correct |
195 ms |
11076 KB |
Output is correct |
10 |
Correct |
137 ms |
7452 KB |
Output is correct |
11 |
Correct |
142 ms |
7520 KB |
Output is correct |
12 |
Correct |
145 ms |
7460 KB |
Output is correct |
13 |
Correct |
135 ms |
7544 KB |
Output is correct |
14 |
Correct |
139 ms |
7596 KB |
Output is correct |
15 |
Correct |
130 ms |
7508 KB |
Output is correct |
16 |
Correct |
126 ms |
7512 KB |
Output is correct |
17 |
Correct |
126 ms |
7692 KB |
Output is correct |
18 |
Correct |
128 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
5 ms |
716 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
6 ms |
696 KB |
Output is correct |
6 |
Correct |
5 ms |
704 KB |
Output is correct |
7 |
Correct |
5 ms |
688 KB |
Output is correct |
8 |
Correct |
6 ms |
696 KB |
Output is correct |
9 |
Correct |
5 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
684 KB |
Output is correct |
11 |
Correct |
5 ms |
684 KB |
Output is correct |
12 |
Correct |
5 ms |
688 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
5 ms |
588 KB |
Output is correct |
15 |
Correct |
5 ms |
688 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
21 ms |
1868 KB |
Output is correct |
20 |
Correct |
24 ms |
2064 KB |
Output is correct |
21 |
Correct |
23 ms |
1996 KB |
Output is correct |
22 |
Correct |
29 ms |
2188 KB |
Output is correct |
23 |
Correct |
22 ms |
1932 KB |
Output is correct |
24 |
Correct |
22 ms |
1840 KB |
Output is correct |
25 |
Correct |
21 ms |
1820 KB |
Output is correct |
26 |
Correct |
21 ms |
1832 KB |
Output is correct |
27 |
Correct |
20 ms |
1792 KB |
Output is correct |
28 |
Correct |
20 ms |
1684 KB |
Output is correct |
29 |
Correct |
34 ms |
3020 KB |
Output is correct |
30 |
Correct |
109 ms |
7076 KB |
Output is correct |
31 |
Correct |
216 ms |
11292 KB |
Output is correct |
32 |
Correct |
211 ms |
11248 KB |
Output is correct |
33 |
Correct |
212 ms |
11240 KB |
Output is correct |
34 |
Correct |
203 ms |
11076 KB |
Output is correct |
35 |
Correct |
194 ms |
11132 KB |
Output is correct |
36 |
Correct |
210 ms |
11232 KB |
Output is correct |
37 |
Correct |
195 ms |
11076 KB |
Output is correct |
38 |
Correct |
137 ms |
7452 KB |
Output is correct |
39 |
Correct |
142 ms |
7520 KB |
Output is correct |
40 |
Correct |
145 ms |
7460 KB |
Output is correct |
41 |
Correct |
135 ms |
7544 KB |
Output is correct |
42 |
Correct |
139 ms |
7596 KB |
Output is correct |
43 |
Correct |
130 ms |
7508 KB |
Output is correct |
44 |
Correct |
126 ms |
7512 KB |
Output is correct |
45 |
Correct |
126 ms |
7692 KB |
Output is correct |
46 |
Correct |
128 ms |
7512 KB |
Output is correct |
47 |
Correct |
901 ms |
37112 KB |
Output is correct |
48 |
Correct |
3563 ms |
105720 KB |
Output is correct |
49 |
Correct |
3947 ms |
113764 KB |
Output is correct |
50 |
Correct |
3912 ms |
113728 KB |
Output is correct |
51 |
Correct |
3959 ms |
113912 KB |
Output is correct |
52 |
Correct |
4046 ms |
113760 KB |
Output is correct |
53 |
Correct |
3916 ms |
113760 KB |
Output is correct |
54 |
Correct |
3536 ms |
113964 KB |
Output is correct |
55 |
Correct |
3802 ms |
113960 KB |
Output is correct |
56 |
Correct |
3523 ms |
113904 KB |
Output is correct |
57 |
Correct |
3891 ms |
113932 KB |
Output is correct |
58 |
Correct |
3712 ms |
113904 KB |
Output is correct |
59 |
Correct |
3075 ms |
104792 KB |
Output is correct |
60 |
Correct |
3099 ms |
104776 KB |
Output is correct |
61 |
Correct |
3001 ms |
104728 KB |
Output is correct |
62 |
Correct |
2798 ms |
100968 KB |
Output is correct |
63 |
Correct |
2937 ms |
100696 KB |
Output is correct |
64 |
Correct |
3151 ms |
100708 KB |
Output is correct |
65 |
Correct |
2800 ms |
96648 KB |
Output is correct |
66 |
Correct |
2707 ms |
96600 KB |
Output is correct |
67 |
Correct |
2726 ms |
96640 KB |
Output is correct |