#include "bubblesort2.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
#define int long long
const int N = 1e6 + 5;
struct ST{
int tree[1 << 21], p[1 << 21];
void push(int x, int lx, int rx){
if(lx == rx || !p[x]) return;
tree[x<<1] += p[x], tree[x<<1|1] += p[x];
p[x<<1] += p[x], p[x<<1|1] += p[x];
p[x] = 0;
}
void add(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x] += v, p[x] += v;
return;
} push(x, lx, rx);
int m = (lx + rx) >> 1;
add(l, r, v, lx, m, x<<1), add(l, r, v, m+1, rx, x<<1|1);
tree[x] = max(tree[x<<1], tree[x<<1|1]);
}
}tree;
#define i32 int32_t
vector<i32> countScans(vector<i32> X, vector<i32> in, vector<i32> Y){
vector<int> a, val;
for(auto x : X) a.push_back(x);
for(auto x : Y) val.push_back(x);
int n = (int)a.size(), q = (int)in.size();
map<int, int> mm;
for(int i=0;i<n;i++) a[i] = a[i] * n + i, mm[a[i]];
for(int i=0;i<q;i++) val[i] = val[i] * n + in[i], mm[val[i]];
{
int in = 0;
for(auto& x : mm) x.second = in++;
for(int i=0;i<n;i++) a[i] = mm[a[i]];
for(int i=0;i<q;i++) val[i] = mm[val[i]];
}
for(int i=0;i<n;i++) tree.add(a[i], a[i], i), tree.add(a[i] + 1, N, -1);
vector<i32> res;
for(int j=0;j<q;j++){
int i = in[j], v = val[j];
tree.add(a[i] + 1, N, +1);
tree.add(a[i], a[i], -i);
a[i] = v;
tree.add(a[i], a[i], i);
tree.add(a[i] + 1, N, -1);
res.push_back(tree.tree[1]);
} return res;
}
/*
4 2
1 2 3 4
0 3
2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Correct |
2 ms |
568 KB |
Output is correct |
3 |
Correct |
5 ms |
820 KB |
Output is correct |
4 |
Correct |
5 ms |
844 KB |
Output is correct |
5 |
Correct |
5 ms |
848 KB |
Output is correct |
6 |
Correct |
5 ms |
816 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
7 ms |
844 KB |
Output is correct |
11 |
Correct |
5 ms |
836 KB |
Output is correct |
12 |
Correct |
6 ms |
844 KB |
Output is correct |
13 |
Correct |
7 ms |
824 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
7 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
712 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Correct |
2 ms |
568 KB |
Output is correct |
3 |
Correct |
5 ms |
820 KB |
Output is correct |
4 |
Correct |
5 ms |
844 KB |
Output is correct |
5 |
Correct |
5 ms |
848 KB |
Output is correct |
6 |
Correct |
5 ms |
816 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
7 ms |
844 KB |
Output is correct |
11 |
Correct |
5 ms |
836 KB |
Output is correct |
12 |
Correct |
6 ms |
844 KB |
Output is correct |
13 |
Correct |
7 ms |
824 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
7 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
712 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
21 ms |
2252 KB |
Output is correct |
20 |
Correct |
22 ms |
2496 KB |
Output is correct |
21 |
Correct |
19 ms |
2516 KB |
Output is correct |
22 |
Correct |
19 ms |
2448 KB |
Output is correct |
23 |
Correct |
18 ms |
2284 KB |
Output is correct |
24 |
Correct |
27 ms |
2244 KB |
Output is correct |
25 |
Correct |
18 ms |
2208 KB |
Output is correct |
26 |
Correct |
17 ms |
2132 KB |
Output is correct |
27 |
Correct |
17 ms |
2076 KB |
Output is correct |
28 |
Correct |
17 ms |
2036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
3748 KB |
Output is correct |
2 |
Correct |
95 ms |
8236 KB |
Output is correct |
3 |
Correct |
155 ms |
12752 KB |
Output is correct |
4 |
Correct |
139 ms |
12776 KB |
Output is correct |
5 |
Correct |
136 ms |
12684 KB |
Output is correct |
6 |
Correct |
185 ms |
12748 KB |
Output is correct |
7 |
Correct |
133 ms |
12512 KB |
Output is correct |
8 |
Correct |
140 ms |
12632 KB |
Output is correct |
9 |
Correct |
141 ms |
12660 KB |
Output is correct |
10 |
Correct |
112 ms |
8612 KB |
Output is correct |
11 |
Correct |
129 ms |
8588 KB |
Output is correct |
12 |
Correct |
110 ms |
8608 KB |
Output is correct |
13 |
Correct |
98 ms |
8676 KB |
Output is correct |
14 |
Correct |
98 ms |
8672 KB |
Output is correct |
15 |
Correct |
97 ms |
8672 KB |
Output is correct |
16 |
Correct |
92 ms |
8640 KB |
Output is correct |
17 |
Correct |
94 ms |
8656 KB |
Output is correct |
18 |
Correct |
93 ms |
8640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Correct |
2 ms |
568 KB |
Output is correct |
3 |
Correct |
5 ms |
820 KB |
Output is correct |
4 |
Correct |
5 ms |
844 KB |
Output is correct |
5 |
Correct |
5 ms |
848 KB |
Output is correct |
6 |
Correct |
5 ms |
816 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
7 ms |
844 KB |
Output is correct |
11 |
Correct |
5 ms |
836 KB |
Output is correct |
12 |
Correct |
6 ms |
844 KB |
Output is correct |
13 |
Correct |
7 ms |
824 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
7 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
712 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
21 ms |
2252 KB |
Output is correct |
20 |
Correct |
22 ms |
2496 KB |
Output is correct |
21 |
Correct |
19 ms |
2516 KB |
Output is correct |
22 |
Correct |
19 ms |
2448 KB |
Output is correct |
23 |
Correct |
18 ms |
2284 KB |
Output is correct |
24 |
Correct |
27 ms |
2244 KB |
Output is correct |
25 |
Correct |
18 ms |
2208 KB |
Output is correct |
26 |
Correct |
17 ms |
2132 KB |
Output is correct |
27 |
Correct |
17 ms |
2076 KB |
Output is correct |
28 |
Correct |
17 ms |
2036 KB |
Output is correct |
29 |
Correct |
28 ms |
3748 KB |
Output is correct |
30 |
Correct |
95 ms |
8236 KB |
Output is correct |
31 |
Correct |
155 ms |
12752 KB |
Output is correct |
32 |
Correct |
139 ms |
12776 KB |
Output is correct |
33 |
Correct |
136 ms |
12684 KB |
Output is correct |
34 |
Correct |
185 ms |
12748 KB |
Output is correct |
35 |
Correct |
133 ms |
12512 KB |
Output is correct |
36 |
Correct |
140 ms |
12632 KB |
Output is correct |
37 |
Correct |
141 ms |
12660 KB |
Output is correct |
38 |
Correct |
112 ms |
8612 KB |
Output is correct |
39 |
Correct |
129 ms |
8588 KB |
Output is correct |
40 |
Correct |
110 ms |
8608 KB |
Output is correct |
41 |
Correct |
98 ms |
8676 KB |
Output is correct |
42 |
Correct |
98 ms |
8672 KB |
Output is correct |
43 |
Correct |
97 ms |
8672 KB |
Output is correct |
44 |
Correct |
92 ms |
8640 KB |
Output is correct |
45 |
Correct |
94 ms |
8656 KB |
Output is correct |
46 |
Correct |
93 ms |
8640 KB |
Output is correct |
47 |
Correct |
605 ms |
39788 KB |
Output is correct |
48 |
Correct |
2694 ms |
121416 KB |
Output is correct |
49 |
Correct |
3009 ms |
132208 KB |
Output is correct |
50 |
Correct |
2980 ms |
132296 KB |
Output is correct |
51 |
Correct |
2974 ms |
132312 KB |
Output is correct |
52 |
Correct |
2801 ms |
132356 KB |
Output is correct |
53 |
Correct |
2816 ms |
132312 KB |
Output is correct |
54 |
Correct |
2541 ms |
132536 KB |
Output is correct |
55 |
Correct |
2765 ms |
132776 KB |
Output is correct |
56 |
Correct |
2519 ms |
132356 KB |
Output is correct |
57 |
Correct |
2654 ms |
132356 KB |
Output is correct |
58 |
Correct |
2508 ms |
132440 KB |
Output is correct |
59 |
Correct |
2447 ms |
119164 KB |
Output is correct |
60 |
Correct |
2433 ms |
119272 KB |
Output is correct |
61 |
Correct |
2483 ms |
119200 KB |
Output is correct |
62 |
Correct |
2457 ms |
113180 KB |
Output is correct |
63 |
Correct |
2455 ms |
113204 KB |
Output is correct |
64 |
Correct |
2407 ms |
113192 KB |
Output is correct |
65 |
Correct |
2436 ms |
106972 KB |
Output is correct |
66 |
Correct |
2517 ms |
106972 KB |
Output is correct |
67 |
Correct |
2423 ms |
107008 KB |
Output is correct |