#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=1e6+5;
int n, q, t;
vector<int> res;
map<pair<int, int>, int> mp;
struct segtree
{
int d[4*nx], lz[4*nx];
void pushlz(int l, int r, int i)
{
d[i]+=lz[i];
if (l!=r) lz[2*i]+=lz[i], lz[2*i+1]+=lz[i];
lz[i]=0;
}
void update(int l, int r, int i, int ql, int qr, int vl)
{
pushlz(l, r, i);
if (qr<l||r<ql) return;
if (ql<=l&&r<=qr) return lz[i]+=vl, pushlz(l ,r, i), void();
int md=(l+r)/2;
update(l, md, 2*i, ql, qr, vl);
update(md+1, r, 2*i+1, ql, qr, vl);
d[i]=max(d[2*i], d[2*i+1]);
}
} s;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
n=A.size();
q=X.size();
for (int i=0; i<n; i++) mp[{A[i], i}]=0;
for (int i=0; i<q; i++) mp[{V[i], X[i]}]=0;
for (auto &[x, y]:mp) y=++t;
for (int i=0; i<n; i++) s.update(1, n+q, 1, mp[{A[i], i}], mp[{A[i], i}], i), s.update(1, n+q, 1, mp[{A[i], i}], n+q, -1);
for (int i=0; i<q; i++)
{
s.update(1, n+q, 1, mp[{A[X[i]], X[i]}], mp[{A[X[i]], X[i]}], -X[i]);
s.update(1, n+q, 1, mp[{A[X[i]], X[i]}], n+q, 1);
A[X[i]]=V[i];
s.update(1, n+q, 1, mp[{A[X[i]], X[i]}], mp[{A[X[i]], X[i]}], X[i]);
s.update(1, n+q, 1, mp[{A[X[i]], X[i]}], n+q, -1);
res.push_back(s.d[1]+1);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
5 ms |
872 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
5 ms |
756 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
872 KB |
Output is correct |
8 |
Correct |
5 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
5 ms |
872 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
5 ms |
756 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
872 KB |
Output is correct |
8 |
Correct |
5 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
19 ms |
1880 KB |
Output is correct |
20 |
Correct |
24 ms |
2132 KB |
Output is correct |
21 |
Correct |
22 ms |
2076 KB |
Output is correct |
22 |
Correct |
24 ms |
2140 KB |
Output is correct |
23 |
Correct |
24 ms |
1968 KB |
Output is correct |
24 |
Correct |
21 ms |
1884 KB |
Output is correct |
25 |
Correct |
20 ms |
1884 KB |
Output is correct |
26 |
Correct |
21 ms |
1936 KB |
Output is correct |
27 |
Correct |
19 ms |
1884 KB |
Output is correct |
28 |
Correct |
19 ms |
1684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
3164 KB |
Output is correct |
2 |
Correct |
91 ms |
6580 KB |
Output is correct |
3 |
Correct |
176 ms |
12752 KB |
Output is correct |
4 |
Correct |
161 ms |
12732 KB |
Output is correct |
5 |
Correct |
153 ms |
12644 KB |
Output is correct |
6 |
Correct |
187 ms |
12536 KB |
Output is correct |
7 |
Correct |
151 ms |
12504 KB |
Output is correct |
8 |
Correct |
163 ms |
12544 KB |
Output is correct |
9 |
Correct |
151 ms |
12748 KB |
Output is correct |
10 |
Correct |
128 ms |
7228 KB |
Output is correct |
11 |
Correct |
126 ms |
7124 KB |
Output is correct |
12 |
Correct |
125 ms |
7188 KB |
Output is correct |
13 |
Correct |
125 ms |
7380 KB |
Output is correct |
14 |
Correct |
116 ms |
7128 KB |
Output is correct |
15 |
Correct |
118 ms |
7380 KB |
Output is correct |
16 |
Correct |
110 ms |
7380 KB |
Output is correct |
17 |
Correct |
115 ms |
7376 KB |
Output is correct |
18 |
Correct |
113 ms |
7308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
5 ms |
872 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
5 ms |
756 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
872 KB |
Output is correct |
8 |
Correct |
5 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
19 ms |
1880 KB |
Output is correct |
20 |
Correct |
24 ms |
2132 KB |
Output is correct |
21 |
Correct |
22 ms |
2076 KB |
Output is correct |
22 |
Correct |
24 ms |
2140 KB |
Output is correct |
23 |
Correct |
24 ms |
1968 KB |
Output is correct |
24 |
Correct |
21 ms |
1884 KB |
Output is correct |
25 |
Correct |
20 ms |
1884 KB |
Output is correct |
26 |
Correct |
21 ms |
1936 KB |
Output is correct |
27 |
Correct |
19 ms |
1884 KB |
Output is correct |
28 |
Correct |
19 ms |
1684 KB |
Output is correct |
29 |
Correct |
29 ms |
3164 KB |
Output is correct |
30 |
Correct |
91 ms |
6580 KB |
Output is correct |
31 |
Correct |
176 ms |
12752 KB |
Output is correct |
32 |
Correct |
161 ms |
12732 KB |
Output is correct |
33 |
Correct |
153 ms |
12644 KB |
Output is correct |
34 |
Correct |
187 ms |
12536 KB |
Output is correct |
35 |
Correct |
151 ms |
12504 KB |
Output is correct |
36 |
Correct |
163 ms |
12544 KB |
Output is correct |
37 |
Correct |
151 ms |
12748 KB |
Output is correct |
38 |
Correct |
128 ms |
7228 KB |
Output is correct |
39 |
Correct |
126 ms |
7124 KB |
Output is correct |
40 |
Correct |
125 ms |
7188 KB |
Output is correct |
41 |
Correct |
125 ms |
7380 KB |
Output is correct |
42 |
Correct |
116 ms |
7128 KB |
Output is correct |
43 |
Correct |
118 ms |
7380 KB |
Output is correct |
44 |
Correct |
110 ms |
7380 KB |
Output is correct |
45 |
Correct |
115 ms |
7376 KB |
Output is correct |
46 |
Correct |
113 ms |
7308 KB |
Output is correct |
47 |
Correct |
710 ms |
36476 KB |
Output is correct |
48 |
Correct |
2999 ms |
101548 KB |
Output is correct |
49 |
Correct |
3301 ms |
109012 KB |
Output is correct |
50 |
Correct |
3288 ms |
108876 KB |
Output is correct |
51 |
Correct |
3413 ms |
108864 KB |
Output is correct |
52 |
Correct |
3290 ms |
109132 KB |
Output is correct |
53 |
Correct |
3329 ms |
109000 KB |
Output is correct |
54 |
Correct |
3003 ms |
109000 KB |
Output is correct |
55 |
Correct |
3245 ms |
109256 KB |
Output is correct |
56 |
Correct |
2925 ms |
109152 KB |
Output is correct |
57 |
Correct |
3095 ms |
109184 KB |
Output is correct |
58 |
Correct |
3022 ms |
109000 KB |
Output is correct |
59 |
Correct |
2845 ms |
98988 KB |
Output is correct |
60 |
Correct |
2907 ms |
99004 KB |
Output is correct |
61 |
Correct |
2847 ms |
98940 KB |
Output is correct |
62 |
Correct |
2730 ms |
94364 KB |
Output is correct |
63 |
Correct |
2480 ms |
94316 KB |
Output is correct |
64 |
Correct |
2546 ms |
94344 KB |
Output is correct |
65 |
Correct |
2456 ms |
89680 KB |
Output is correct |
66 |
Correct |
2460 ms |
89816 KB |
Output is correct |
67 |
Correct |
2319 ms |
89672 KB |
Output is correct |