#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(n + q);
for (int i = 0; i < n; ++i) {
pairs[i] = {a[i], i};
}
for (int i = 0; i < q; ++i) {
pairs[n + i] = {v[i], x[i]};
}
sort(pairs.begin(), pairs.end());
pairs.erase(unique(pairs.begin(), pairs.end()), pairs.end());
int N = pairs.size();
ST t(N);
auto update = [&](const int &index, const int &pos, const int &sgn) -> void {
t.update(index, index, sgn * (INF + pos));
t.update(index + 1, N - 1, -sgn);
};
auto getIndex = [&](const pair<int, int> &p) -> int {
return distance(pairs.begin(), lower_bound(pairs.begin(), pairs.end(), p));
};
for (int i = 0; i < n; ++i) {
update(getIndex({a[i], i}), i, 1);
}
vector<int> sol(q);
for (int i = 0; i < q; ++i) {
update(getIndex({a[x[i]], x[i]}), x[i], -1);
a[x[i]] = v[i];
update(getIndex({a[x[i]], x[i]}), x[i], 1);
sol[i] = t.getMax();
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
14 ms |
844 KB |
Output is correct |
20 |
Correct |
15 ms |
880 KB |
Output is correct |
21 |
Correct |
16 ms |
844 KB |
Output is correct |
22 |
Correct |
15 ms |
844 KB |
Output is correct |
23 |
Correct |
15 ms |
844 KB |
Output is correct |
24 |
Correct |
15 ms |
844 KB |
Output is correct |
25 |
Correct |
14 ms |
844 KB |
Output is correct |
26 |
Correct |
18 ms |
844 KB |
Output is correct |
27 |
Correct |
18 ms |
844 KB |
Output is correct |
28 |
Correct |
15 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1348 KB |
Output is correct |
2 |
Correct |
65 ms |
2532 KB |
Output is correct |
3 |
Correct |
114 ms |
4416 KB |
Output is correct |
4 |
Correct |
122 ms |
4564 KB |
Output is correct |
5 |
Correct |
114 ms |
4432 KB |
Output is correct |
6 |
Correct |
127 ms |
4560 KB |
Output is correct |
7 |
Correct |
113 ms |
4436 KB |
Output is correct |
8 |
Correct |
119 ms |
4440 KB |
Output is correct |
9 |
Correct |
114 ms |
4460 KB |
Output is correct |
10 |
Correct |
90 ms |
3412 KB |
Output is correct |
11 |
Correct |
94 ms |
3396 KB |
Output is correct |
12 |
Correct |
89 ms |
3404 KB |
Output is correct |
13 |
Correct |
87 ms |
3416 KB |
Output is correct |
14 |
Correct |
89 ms |
3476 KB |
Output is correct |
15 |
Correct |
98 ms |
3396 KB |
Output is correct |
16 |
Correct |
107 ms |
3396 KB |
Output is correct |
17 |
Correct |
86 ms |
3396 KB |
Output is correct |
18 |
Correct |
105 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
14 ms |
844 KB |
Output is correct |
20 |
Correct |
15 ms |
880 KB |
Output is correct |
21 |
Correct |
16 ms |
844 KB |
Output is correct |
22 |
Correct |
15 ms |
844 KB |
Output is correct |
23 |
Correct |
15 ms |
844 KB |
Output is correct |
24 |
Correct |
15 ms |
844 KB |
Output is correct |
25 |
Correct |
14 ms |
844 KB |
Output is correct |
26 |
Correct |
18 ms |
844 KB |
Output is correct |
27 |
Correct |
18 ms |
844 KB |
Output is correct |
28 |
Correct |
15 ms |
844 KB |
Output is correct |
29 |
Correct |
27 ms |
1348 KB |
Output is correct |
30 |
Correct |
65 ms |
2532 KB |
Output is correct |
31 |
Correct |
114 ms |
4416 KB |
Output is correct |
32 |
Correct |
122 ms |
4564 KB |
Output is correct |
33 |
Correct |
114 ms |
4432 KB |
Output is correct |
34 |
Correct |
127 ms |
4560 KB |
Output is correct |
35 |
Correct |
113 ms |
4436 KB |
Output is correct |
36 |
Correct |
119 ms |
4440 KB |
Output is correct |
37 |
Correct |
114 ms |
4460 KB |
Output is correct |
38 |
Correct |
90 ms |
3412 KB |
Output is correct |
39 |
Correct |
94 ms |
3396 KB |
Output is correct |
40 |
Correct |
89 ms |
3404 KB |
Output is correct |
41 |
Correct |
87 ms |
3416 KB |
Output is correct |
42 |
Correct |
89 ms |
3476 KB |
Output is correct |
43 |
Correct |
98 ms |
3396 KB |
Output is correct |
44 |
Correct |
107 ms |
3396 KB |
Output is correct |
45 |
Correct |
86 ms |
3396 KB |
Output is correct |
46 |
Correct |
105 ms |
3408 KB |
Output is correct |
47 |
Correct |
440 ms |
14800 KB |
Output is correct |
48 |
Correct |
1855 ms |
36668 KB |
Output is correct |
49 |
Correct |
1968 ms |
38372 KB |
Output is correct |
50 |
Correct |
2047 ms |
38208 KB |
Output is correct |
51 |
Correct |
1957 ms |
38252 KB |
Output is correct |
52 |
Correct |
2001 ms |
38304 KB |
Output is correct |
53 |
Correct |
1967 ms |
38208 KB |
Output is correct |
54 |
Correct |
1903 ms |
38212 KB |
Output is correct |
55 |
Correct |
2096 ms |
38256 KB |
Output is correct |
56 |
Correct |
1906 ms |
38336 KB |
Output is correct |
57 |
Correct |
1952 ms |
38216 KB |
Output is correct |
58 |
Correct |
1759 ms |
38260 KB |
Output is correct |
59 |
Correct |
1640 ms |
38332 KB |
Output is correct |
60 |
Correct |
1597 ms |
38216 KB |
Output is correct |
61 |
Correct |
1714 ms |
38172 KB |
Output is correct |
62 |
Correct |
1547 ms |
38252 KB |
Output is correct |
63 |
Correct |
1499 ms |
38264 KB |
Output is correct |
64 |
Correct |
1551 ms |
38288 KB |
Output is correct |
65 |
Correct |
1371 ms |
38252 KB |
Output is correct |
66 |
Correct |
1379 ms |
38252 KB |
Output is correct |
67 |
Correct |
1399 ms |
38216 KB |
Output is correct |