#include "bubblesort2.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 100;
struct seg{
vector <int> st, laz;
void ass(int n) {
st.assign(n * 4 + 100, 0);
laz.assign(n * 4 + 100, 0);
}
void push(int id) {
int t = laz[id];
laz[id * 2] += t;
laz[id * 2 + 1] += t;
st[id * 2] += t;
st[id * 2 + 1] += t;
laz[id] = 0;
}
void upd(int id, int l, int r, int u, int v, int c) {
if (l > v || r < u || u > v)
return;
if (l >= u && r <= v) {
st[id] += c;
laz[id] += c;
return;
}
push(id);
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, c);
upd(id * 2 + 1, m + 1, r, u, v, c);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get() {
return st[1];
}
};
set <int> pos[N];
int a[N], used[N];
vector <int> countScans(vector <int> A, vector <int> X, vector <int> V) {
map <int, int> mp;
for (auto &x : A)
mp[x];
for (auto &x : V)
mp[x];
int sz = 0;
for (auto &x : mp) {
sz++;
x.s = sz;
}
seg st;
st.ass(sz);
int n = sz(A);
for (int i = 0; i < n; i++) {
A[i] = mp[A[i]];
a[i + 1] = A[i];
pos[a[i + 1]].insert(i + 1);
}
for (auto &x : V)
x = mp[x];
for (int i = n; i >= 1; i--) {
if (used[a[i]] == 0) {
used[a[i]] = 1;
st.upd(1, 1, sz, a[i], a[i], i);
}
st.upd(1, 1, sz, a[i], sz, -1);
}
vector <int> ans;
int q = sz(X);
for (int i = 0; i < q; i++) {
X[i]++;
int v = a[X[i]], nx = V[i];
st.upd(1, 1, sz, v, sz, 1);
st.upd(1, 1, sz, nx, sz, -1);
if (*(--pos[v].end()) == X[i]) {
if (sz(pos[v]) == 1) {
st.upd(1, 1, sz, v, v, -X[i]);
} else {
auto it = (--pos[v].end());
it--;
st.upd(1, 1, sz, v, v, -(X[i] - (*it)));
}
}
pos[v].erase(X[i]);
a[X[i]] = nx;
if (pos[nx].empty() || *(--pos[nx].end()) < X[i]) {
int add = X[i];
if (sz(pos[nx])) {
add -= *(--pos[nx].end());
}
st.upd(1, 1, sz, nx, nx, add);
}
pos[nx].insert(X[i]);
ans.pb(max(0, st.get()));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
51028 KB |
Output is correct |
2 |
Correct |
13 ms |
51288 KB |
Output is correct |
3 |
Correct |
17 ms |
51292 KB |
Output is correct |
4 |
Correct |
14 ms |
51456 KB |
Output is correct |
5 |
Correct |
15 ms |
51292 KB |
Output is correct |
6 |
Correct |
14 ms |
51424 KB |
Output is correct |
7 |
Correct |
15 ms |
51292 KB |
Output is correct |
8 |
Correct |
15 ms |
51292 KB |
Output is correct |
9 |
Correct |
15 ms |
51408 KB |
Output is correct |
10 |
Correct |
15 ms |
51412 KB |
Output is correct |
11 |
Correct |
16 ms |
51192 KB |
Output is correct |
12 |
Correct |
14 ms |
51288 KB |
Output is correct |
13 |
Correct |
15 ms |
51288 KB |
Output is correct |
14 |
Correct |
14 ms |
51292 KB |
Output is correct |
15 |
Correct |
14 ms |
51548 KB |
Output is correct |
16 |
Correct |
16 ms |
51548 KB |
Output is correct |
17 |
Correct |
14 ms |
51292 KB |
Output is correct |
18 |
Correct |
14 ms |
51292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
51028 KB |
Output is correct |
2 |
Correct |
13 ms |
51288 KB |
Output is correct |
3 |
Correct |
17 ms |
51292 KB |
Output is correct |
4 |
Correct |
14 ms |
51456 KB |
Output is correct |
5 |
Correct |
15 ms |
51292 KB |
Output is correct |
6 |
Correct |
14 ms |
51424 KB |
Output is correct |
7 |
Correct |
15 ms |
51292 KB |
Output is correct |
8 |
Correct |
15 ms |
51292 KB |
Output is correct |
9 |
Correct |
15 ms |
51408 KB |
Output is correct |
10 |
Correct |
15 ms |
51412 KB |
Output is correct |
11 |
Correct |
16 ms |
51192 KB |
Output is correct |
12 |
Correct |
14 ms |
51288 KB |
Output is correct |
13 |
Correct |
15 ms |
51288 KB |
Output is correct |
14 |
Correct |
14 ms |
51292 KB |
Output is correct |
15 |
Correct |
14 ms |
51548 KB |
Output is correct |
16 |
Correct |
16 ms |
51548 KB |
Output is correct |
17 |
Correct |
14 ms |
51292 KB |
Output is correct |
18 |
Correct |
14 ms |
51292 KB |
Output is correct |
19 |
Correct |
26 ms |
52568 KB |
Output is correct |
20 |
Correct |
28 ms |
52824 KB |
Output is correct |
21 |
Correct |
27 ms |
52828 KB |
Output is correct |
22 |
Correct |
29 ms |
52828 KB |
Output is correct |
23 |
Correct |
26 ms |
52572 KB |
Output is correct |
24 |
Correct |
27 ms |
52572 KB |
Output is correct |
25 |
Correct |
29 ms |
52572 KB |
Output is correct |
26 |
Correct |
26 ms |
52532 KB |
Output is correct |
27 |
Correct |
26 ms |
52572 KB |
Output is correct |
28 |
Correct |
26 ms |
52572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
52312 KB |
Output is correct |
2 |
Correct |
42 ms |
53952 KB |
Output is correct |
3 |
Correct |
66 ms |
55384 KB |
Output is correct |
4 |
Correct |
64 ms |
55380 KB |
Output is correct |
5 |
Correct |
63 ms |
55452 KB |
Output is correct |
6 |
Correct |
68 ms |
55324 KB |
Output is correct |
7 |
Correct |
61 ms |
55392 KB |
Output is correct |
8 |
Correct |
62 ms |
55592 KB |
Output is correct |
9 |
Correct |
62 ms |
55388 KB |
Output is correct |
10 |
Correct |
54 ms |
55376 KB |
Output is correct |
11 |
Correct |
54 ms |
55380 KB |
Output is correct |
12 |
Correct |
54 ms |
55388 KB |
Output is correct |
13 |
Correct |
53 ms |
55376 KB |
Output is correct |
14 |
Correct |
57 ms |
55380 KB |
Output is correct |
15 |
Correct |
53 ms |
55404 KB |
Output is correct |
16 |
Correct |
50 ms |
55440 KB |
Output is correct |
17 |
Correct |
50 ms |
55368 KB |
Output is correct |
18 |
Correct |
50 ms |
55416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
51028 KB |
Output is correct |
2 |
Correct |
13 ms |
51288 KB |
Output is correct |
3 |
Correct |
17 ms |
51292 KB |
Output is correct |
4 |
Correct |
14 ms |
51456 KB |
Output is correct |
5 |
Correct |
15 ms |
51292 KB |
Output is correct |
6 |
Correct |
14 ms |
51424 KB |
Output is correct |
7 |
Correct |
15 ms |
51292 KB |
Output is correct |
8 |
Correct |
15 ms |
51292 KB |
Output is correct |
9 |
Correct |
15 ms |
51408 KB |
Output is correct |
10 |
Correct |
15 ms |
51412 KB |
Output is correct |
11 |
Correct |
16 ms |
51192 KB |
Output is correct |
12 |
Correct |
14 ms |
51288 KB |
Output is correct |
13 |
Correct |
15 ms |
51288 KB |
Output is correct |
14 |
Correct |
14 ms |
51292 KB |
Output is correct |
15 |
Correct |
14 ms |
51548 KB |
Output is correct |
16 |
Correct |
16 ms |
51548 KB |
Output is correct |
17 |
Correct |
14 ms |
51292 KB |
Output is correct |
18 |
Correct |
14 ms |
51292 KB |
Output is correct |
19 |
Correct |
26 ms |
52568 KB |
Output is correct |
20 |
Correct |
28 ms |
52824 KB |
Output is correct |
21 |
Correct |
27 ms |
52828 KB |
Output is correct |
22 |
Correct |
29 ms |
52828 KB |
Output is correct |
23 |
Correct |
26 ms |
52572 KB |
Output is correct |
24 |
Correct |
27 ms |
52572 KB |
Output is correct |
25 |
Correct |
29 ms |
52572 KB |
Output is correct |
26 |
Correct |
26 ms |
52532 KB |
Output is correct |
27 |
Correct |
26 ms |
52572 KB |
Output is correct |
28 |
Correct |
26 ms |
52572 KB |
Output is correct |
29 |
Correct |
23 ms |
52312 KB |
Output is correct |
30 |
Correct |
42 ms |
53952 KB |
Output is correct |
31 |
Correct |
66 ms |
55384 KB |
Output is correct |
32 |
Correct |
64 ms |
55380 KB |
Output is correct |
33 |
Correct |
63 ms |
55452 KB |
Output is correct |
34 |
Correct |
68 ms |
55324 KB |
Output is correct |
35 |
Correct |
61 ms |
55392 KB |
Output is correct |
36 |
Correct |
62 ms |
55592 KB |
Output is correct |
37 |
Correct |
62 ms |
55388 KB |
Output is correct |
38 |
Correct |
54 ms |
55376 KB |
Output is correct |
39 |
Correct |
54 ms |
55380 KB |
Output is correct |
40 |
Correct |
54 ms |
55388 KB |
Output is correct |
41 |
Correct |
53 ms |
55376 KB |
Output is correct |
42 |
Correct |
57 ms |
55380 KB |
Output is correct |
43 |
Correct |
53 ms |
55404 KB |
Output is correct |
44 |
Correct |
50 ms |
55440 KB |
Output is correct |
45 |
Correct |
50 ms |
55368 KB |
Output is correct |
46 |
Correct |
50 ms |
55416 KB |
Output is correct |
47 |
Correct |
606 ms |
93164 KB |
Output is correct |
48 |
Correct |
2820 ms |
171976 KB |
Output is correct |
49 |
Correct |
3104 ms |
183548 KB |
Output is correct |
50 |
Correct |
3315 ms |
183724 KB |
Output is correct |
51 |
Correct |
3269 ms |
183808 KB |
Output is correct |
52 |
Correct |
3118 ms |
183832 KB |
Output is correct |
53 |
Correct |
3034 ms |
183724 KB |
Output is correct |
54 |
Correct |
3116 ms |
183736 KB |
Output is correct |
55 |
Correct |
3478 ms |
183708 KB |
Output is correct |
56 |
Correct |
3146 ms |
184300 KB |
Output is correct |
57 |
Correct |
3114 ms |
183920 KB |
Output is correct |
58 |
Correct |
3156 ms |
183312 KB |
Output is correct |
59 |
Correct |
2562 ms |
172720 KB |
Output is correct |
60 |
Correct |
2713 ms |
172820 KB |
Output is correct |
61 |
Correct |
2718 ms |
172876 KB |
Output is correct |
62 |
Correct |
2480 ms |
167828 KB |
Output is correct |
63 |
Correct |
2556 ms |
167756 KB |
Output is correct |
64 |
Correct |
2438 ms |
167616 KB |
Output is correct |
65 |
Correct |
2353 ms |
162560 KB |
Output is correct |
66 |
Correct |
2366 ms |
162676 KB |
Output is correct |
67 |
Correct |
2247 ms |
162552 KB |
Output is correct |