#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 1e6+10;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
const int inf = 0x3f3f3f3f;
int n, q;
int tour[treesiz], prop[treesiz];
vector< pair<int, int> > v;
void send(int x) {
tour[x * 2] += prop[x];
tour[x * 2 + 1] += prop[x];
prop[x * 2] += prop[x];
prop[x * 2 + 1] += prop[x];
prop[x] = 0;
}
void update(int a, int b, int l, int r, int node, int val) {
if (l > b || r < a) return;
if (l >= a && r <= b) {
tour[node] += val;
prop[node] += val;
return;
}
int mid = (l + r) / 2;
send(node);
update(a, b, l, mid, node * 2, val);
update(a, b, mid + 1, r, node * 2 + 1, val);
tour[node] = max(tour[node * 2], tour[node * 2 + 1]);
}
int query(int a, int b, int l, int r, int node) {
if (l > b || r < a) return -inf;
if (l >= a && r <= b) return tour[node];
int mid = (l + r) / 2;
send(node);
return max(query(a, b, l, mid, node * 2), query(a, b, mid + 1, r, node * 2 + 1));
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> vs){
n = a.size();
q = x.size();
vector< int > ans;
for (int i = 0; i < n; i++) {
v.push_back(make_pair(a[i], i));
}
for (int i = 0; i < q; i++) {
v.push_back(make_pair(vs[i], x[i]));
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for (int i = 0; i < n; i++)
a[i] = lower_bound(v.begin(), v.end(), make_pair(a[i], i)) - v.begin();
update(0, off - 1, 0, off - 1, 1, -inf);
for (int i = 0; i < n; i++) {
update(a[i], a[i], 0, off - 1, 1, inf + i);
update(a[i] + 1, off - 1, 0, off - 1, 1, -1);
}
for (int i = 0; i < q; i++) {
int ind = x[i];
update(a[ind], a[ind], 0, off - 1, 1, -inf - ind);
update(a[ind] + 1, off - 1, 0, off - 1, 1, 1);
a[ind] = lower_bound(v.begin(), v.end(), make_pair(vs[i], x[i])) - v.begin();
update(a[ind], a[ind], 0, off - 1, 1, inf + ind);
update(a[ind] + 1, off - 1, 0, off - 1, 1, -1);
ans.push_back(query(0, off - 1, 0, off - 1, 1));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
9 ms |
588 KB |
Output is correct |
4 |
Correct |
7 ms |
588 KB |
Output is correct |
5 |
Correct |
7 ms |
568 KB |
Output is correct |
6 |
Correct |
7 ms |
620 KB |
Output is correct |
7 |
Correct |
7 ms |
712 KB |
Output is correct |
8 |
Correct |
7 ms |
588 KB |
Output is correct |
9 |
Correct |
7 ms |
568 KB |
Output is correct |
10 |
Correct |
7 ms |
588 KB |
Output is correct |
11 |
Correct |
7 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
588 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
588 KB |
Output is correct |
16 |
Correct |
6 ms |
588 KB |
Output is correct |
17 |
Correct |
7 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
9 ms |
588 KB |
Output is correct |
4 |
Correct |
7 ms |
588 KB |
Output is correct |
5 |
Correct |
7 ms |
568 KB |
Output is correct |
6 |
Correct |
7 ms |
620 KB |
Output is correct |
7 |
Correct |
7 ms |
712 KB |
Output is correct |
8 |
Correct |
7 ms |
588 KB |
Output is correct |
9 |
Correct |
7 ms |
568 KB |
Output is correct |
10 |
Correct |
7 ms |
588 KB |
Output is correct |
11 |
Correct |
7 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
588 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
588 KB |
Output is correct |
16 |
Correct |
6 ms |
588 KB |
Output is correct |
17 |
Correct |
7 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
23 ms |
1208 KB |
Output is correct |
20 |
Correct |
26 ms |
1292 KB |
Output is correct |
21 |
Correct |
26 ms |
1304 KB |
Output is correct |
22 |
Correct |
26 ms |
1296 KB |
Output is correct |
23 |
Correct |
26 ms |
1172 KB |
Output is correct |
24 |
Correct |
26 ms |
1228 KB |
Output is correct |
25 |
Correct |
26 ms |
1164 KB |
Output is correct |
26 |
Correct |
26 ms |
1160 KB |
Output is correct |
27 |
Correct |
27 ms |
1144 KB |
Output is correct |
28 |
Correct |
25 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1568 KB |
Output is correct |
2 |
Correct |
98 ms |
3100 KB |
Output is correct |
3 |
Correct |
166 ms |
4920 KB |
Output is correct |
4 |
Correct |
179 ms |
4952 KB |
Output is correct |
5 |
Correct |
167 ms |
4920 KB |
Output is correct |
6 |
Correct |
165 ms |
4908 KB |
Output is correct |
7 |
Correct |
164 ms |
4792 KB |
Output is correct |
8 |
Correct |
166 ms |
4884 KB |
Output is correct |
9 |
Correct |
165 ms |
4884 KB |
Output is correct |
10 |
Correct |
151 ms |
4280 KB |
Output is correct |
11 |
Correct |
154 ms |
4332 KB |
Output is correct |
12 |
Correct |
153 ms |
4312 KB |
Output is correct |
13 |
Correct |
154 ms |
4244 KB |
Output is correct |
14 |
Correct |
149 ms |
4192 KB |
Output is correct |
15 |
Correct |
149 ms |
4192 KB |
Output is correct |
16 |
Correct |
149 ms |
4252 KB |
Output is correct |
17 |
Correct |
147 ms |
4300 KB |
Output is correct |
18 |
Correct |
144 ms |
4280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
9 ms |
588 KB |
Output is correct |
4 |
Correct |
7 ms |
588 KB |
Output is correct |
5 |
Correct |
7 ms |
568 KB |
Output is correct |
6 |
Correct |
7 ms |
620 KB |
Output is correct |
7 |
Correct |
7 ms |
712 KB |
Output is correct |
8 |
Correct |
7 ms |
588 KB |
Output is correct |
9 |
Correct |
7 ms |
568 KB |
Output is correct |
10 |
Correct |
7 ms |
588 KB |
Output is correct |
11 |
Correct |
7 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
588 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
588 KB |
Output is correct |
16 |
Correct |
6 ms |
588 KB |
Output is correct |
17 |
Correct |
7 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
23 ms |
1208 KB |
Output is correct |
20 |
Correct |
26 ms |
1292 KB |
Output is correct |
21 |
Correct |
26 ms |
1304 KB |
Output is correct |
22 |
Correct |
26 ms |
1296 KB |
Output is correct |
23 |
Correct |
26 ms |
1172 KB |
Output is correct |
24 |
Correct |
26 ms |
1228 KB |
Output is correct |
25 |
Correct |
26 ms |
1164 KB |
Output is correct |
26 |
Correct |
26 ms |
1160 KB |
Output is correct |
27 |
Correct |
27 ms |
1144 KB |
Output is correct |
28 |
Correct |
25 ms |
1152 KB |
Output is correct |
29 |
Correct |
35 ms |
1568 KB |
Output is correct |
30 |
Correct |
98 ms |
3100 KB |
Output is correct |
31 |
Correct |
166 ms |
4920 KB |
Output is correct |
32 |
Correct |
179 ms |
4952 KB |
Output is correct |
33 |
Correct |
167 ms |
4920 KB |
Output is correct |
34 |
Correct |
165 ms |
4908 KB |
Output is correct |
35 |
Correct |
164 ms |
4792 KB |
Output is correct |
36 |
Correct |
166 ms |
4884 KB |
Output is correct |
37 |
Correct |
165 ms |
4884 KB |
Output is correct |
38 |
Correct |
151 ms |
4280 KB |
Output is correct |
39 |
Correct |
154 ms |
4332 KB |
Output is correct |
40 |
Correct |
153 ms |
4312 KB |
Output is correct |
41 |
Correct |
154 ms |
4244 KB |
Output is correct |
42 |
Correct |
149 ms |
4192 KB |
Output is correct |
43 |
Correct |
149 ms |
4192 KB |
Output is correct |
44 |
Correct |
149 ms |
4252 KB |
Output is correct |
45 |
Correct |
147 ms |
4300 KB |
Output is correct |
46 |
Correct |
144 ms |
4280 KB |
Output is correct |
47 |
Correct |
592 ms |
16016 KB |
Output is correct |
48 |
Correct |
2149 ms |
42480 KB |
Output is correct |
49 |
Correct |
2299 ms |
45548 KB |
Output is correct |
50 |
Correct |
2259 ms |
45832 KB |
Output is correct |
51 |
Correct |
2281 ms |
45592 KB |
Output is correct |
52 |
Correct |
2263 ms |
45520 KB |
Output is correct |
53 |
Correct |
2302 ms |
45664 KB |
Output is correct |
54 |
Correct |
2144 ms |
45572 KB |
Output is correct |
55 |
Correct |
2240 ms |
45668 KB |
Output is correct |
56 |
Correct |
2124 ms |
45576 KB |
Output is correct |
57 |
Correct |
2236 ms |
45700 KB |
Output is correct |
58 |
Correct |
2153 ms |
45616 KB |
Output is correct |
59 |
Correct |
2012 ms |
43688 KB |
Output is correct |
60 |
Correct |
2008 ms |
43636 KB |
Output is correct |
61 |
Correct |
1991 ms |
43696 KB |
Output is correct |
62 |
Correct |
1968 ms |
42656 KB |
Output is correct |
63 |
Correct |
1996 ms |
42912 KB |
Output is correct |
64 |
Correct |
1949 ms |
42668 KB |
Output is correct |
65 |
Correct |
1869 ms |
41812 KB |
Output is correct |
66 |
Correct |
1882 ms |
41584 KB |
Output is correct |
67 |
Correct |
1855 ms |
41676 KB |
Output is correct |