#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int Off = 1<<20;
struct SegTree {
int a[2 * Off], lazy[2 * Off];
set<int> inds[Off];
SegTree() {
for (int i = 1; i < 2 * Off; i++) a[i] = -1e9;
for (int i = 0; i < Off; i++) inds[i].insert(-1e9);
}
void propagate(int i) {
a[i] += lazy[i];
if (i < Off) {
lazy[2 * i] += lazy[i];
lazy[2 * i + 1] += lazy[i];
}
lazy[i] = 0;
}
void update_path(int j, int i = 1, int lo = 0, int hi = Off) {
propagate(i);
if (lo + 1 == hi) return;
if (lo > j || j >= hi) return;
int mid = (lo + hi) / 2;
update_path(j, 2 * i, lo, mid);
update_path(j, 2 * i + 1, mid, hi);
a[i] = max(a[2 * i], a[2 * i + 1]);
}
void update_inds(int i, int ind, bool add) {
a[i + Off] -= *inds[i].rbegin();
if (add) inds[i].insert(ind);
else inds[i].erase(ind);
a[i + Off] += *inds[i].rbegin();
update_path(i);
}
void update_segment(int l, int r, int val, int i = 1, int lo = 0, int hi = Off) {
propagate(i);
if (r <= lo || hi <= l) return;
if (l <= lo && hi <= r) {
lazy[i] += val;
propagate(i);
} else {
int mid = (lo + hi) / 2;
update_segment(l, r, val, 2 * i, lo, mid);
update_segment(l, r, val, 2 * i + 1, mid, hi);
a[i] = max(a[2 * i], a[2 * i + 1]);
}
}
void update_segment(int i, bool add) {
if (add) update_segment(i + 1, Off, -1);
else update_segment(i + 1, Off, 1);
}
int query() {
propagate(1);
return a[1];
}
} T;
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
int n = a.size(), q = x.size();
vector<int> answer(q);
vector<tuple<int, int, int>> val;
map<int, int> compress;
for (int i = 0; i < n; i++) val.push_back(make_tuple(a[i], i, i));
for (int i = 0; i < q; i++) val.push_back(make_tuple(v[i], x[i], i + n));
sort(val.begin(), val.end());
for (int i = 0; i < (int)val.size(); i++)
compress[get<2>(val[i])] = i;
for (int i = 0; i < n; i++) {
int t = compress[i];
T.update_inds(t, i, true);
T.update_segment(t, true);
}
for (int i = 0; i < n; i++) a[i] = i;
for (int i = 0; i < q; i++) {
int t = compress[a[x[i]]];
T.update_inds(t, x[i], false);
T.update_segment(t, false);
a[x[i]] = i + n;
t = compress[i + n];
T.update_inds(t, x[i], true);
T.update_segment(t, true);
answer[i] = T.query();
}
vector<int> vvv;
if(n > 50000) return vvv;
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
107136 KB |
Output is correct |
2 |
Correct |
170 ms |
107236 KB |
Output is correct |
3 |
Correct |
176 ms |
107568 KB |
Output is correct |
4 |
Correct |
186 ms |
107652 KB |
Output is correct |
5 |
Correct |
158 ms |
107764 KB |
Output is correct |
6 |
Correct |
167 ms |
107764 KB |
Output is correct |
7 |
Correct |
173 ms |
107812 KB |
Output is correct |
8 |
Correct |
168 ms |
107812 KB |
Output is correct |
9 |
Correct |
169 ms |
107812 KB |
Output is correct |
10 |
Correct |
180 ms |
107812 KB |
Output is correct |
11 |
Correct |
163 ms |
107812 KB |
Output is correct |
12 |
Correct |
185 ms |
107820 KB |
Output is correct |
13 |
Correct |
168 ms |
107820 KB |
Output is correct |
14 |
Correct |
195 ms |
107820 KB |
Output is correct |
15 |
Correct |
163 ms |
107820 KB |
Output is correct |
16 |
Correct |
190 ms |
107888 KB |
Output is correct |
17 |
Correct |
173 ms |
107888 KB |
Output is correct |
18 |
Correct |
164 ms |
107888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
107136 KB |
Output is correct |
2 |
Correct |
170 ms |
107236 KB |
Output is correct |
3 |
Correct |
176 ms |
107568 KB |
Output is correct |
4 |
Correct |
186 ms |
107652 KB |
Output is correct |
5 |
Correct |
158 ms |
107764 KB |
Output is correct |
6 |
Correct |
167 ms |
107764 KB |
Output is correct |
7 |
Correct |
173 ms |
107812 KB |
Output is correct |
8 |
Correct |
168 ms |
107812 KB |
Output is correct |
9 |
Correct |
169 ms |
107812 KB |
Output is correct |
10 |
Correct |
180 ms |
107812 KB |
Output is correct |
11 |
Correct |
163 ms |
107812 KB |
Output is correct |
12 |
Correct |
185 ms |
107820 KB |
Output is correct |
13 |
Correct |
168 ms |
107820 KB |
Output is correct |
14 |
Correct |
195 ms |
107820 KB |
Output is correct |
15 |
Correct |
163 ms |
107820 KB |
Output is correct |
16 |
Correct |
190 ms |
107888 KB |
Output is correct |
17 |
Correct |
173 ms |
107888 KB |
Output is correct |
18 |
Correct |
164 ms |
107888 KB |
Output is correct |
19 |
Correct |
194 ms |
108888 KB |
Output is correct |
20 |
Correct |
213 ms |
109000 KB |
Output is correct |
21 |
Correct |
217 ms |
109148 KB |
Output is correct |
22 |
Correct |
211 ms |
109148 KB |
Output is correct |
23 |
Correct |
198 ms |
109148 KB |
Output is correct |
24 |
Correct |
168 ms |
109148 KB |
Output is correct |
25 |
Correct |
200 ms |
109148 KB |
Output is correct |
26 |
Correct |
214 ms |
109148 KB |
Output is correct |
27 |
Correct |
183 ms |
109220 KB |
Output is correct |
28 |
Correct |
167 ms |
109220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
203 ms |
110892 KB |
Output is correct |
2 |
Correct |
355 ms |
114364 KB |
Output is correct |
3 |
Correct |
524 ms |
117836 KB |
Output is correct |
4 |
Correct |
512 ms |
117836 KB |
Output is correct |
5 |
Correct |
469 ms |
117836 KB |
Output is correct |
6 |
Correct |
552 ms |
117836 KB |
Output is correct |
7 |
Correct |
613 ms |
117836 KB |
Output is correct |
8 |
Correct |
464 ms |
117852 KB |
Output is correct |
9 |
Correct |
444 ms |
117916 KB |
Output is correct |
10 |
Correct |
431 ms |
117916 KB |
Output is correct |
11 |
Correct |
446 ms |
117916 KB |
Output is correct |
12 |
Correct |
414 ms |
117936 KB |
Output is correct |
13 |
Correct |
375 ms |
117936 KB |
Output is correct |
14 |
Correct |
430 ms |
117936 KB |
Output is correct |
15 |
Correct |
457 ms |
117936 KB |
Output is correct |
16 |
Correct |
388 ms |
117936 KB |
Output is correct |
17 |
Correct |
503 ms |
117936 KB |
Output is correct |
18 |
Correct |
404 ms |
117936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
107136 KB |
Output is correct |
2 |
Correct |
170 ms |
107236 KB |
Output is correct |
3 |
Correct |
176 ms |
107568 KB |
Output is correct |
4 |
Correct |
186 ms |
107652 KB |
Output is correct |
5 |
Correct |
158 ms |
107764 KB |
Output is correct |
6 |
Correct |
167 ms |
107764 KB |
Output is correct |
7 |
Correct |
173 ms |
107812 KB |
Output is correct |
8 |
Correct |
168 ms |
107812 KB |
Output is correct |
9 |
Correct |
169 ms |
107812 KB |
Output is correct |
10 |
Correct |
180 ms |
107812 KB |
Output is correct |
11 |
Correct |
163 ms |
107812 KB |
Output is correct |
12 |
Correct |
185 ms |
107820 KB |
Output is correct |
13 |
Correct |
168 ms |
107820 KB |
Output is correct |
14 |
Correct |
195 ms |
107820 KB |
Output is correct |
15 |
Correct |
163 ms |
107820 KB |
Output is correct |
16 |
Correct |
190 ms |
107888 KB |
Output is correct |
17 |
Correct |
173 ms |
107888 KB |
Output is correct |
18 |
Correct |
164 ms |
107888 KB |
Output is correct |
19 |
Correct |
194 ms |
108888 KB |
Output is correct |
20 |
Correct |
213 ms |
109000 KB |
Output is correct |
21 |
Correct |
217 ms |
109148 KB |
Output is correct |
22 |
Correct |
211 ms |
109148 KB |
Output is correct |
23 |
Correct |
198 ms |
109148 KB |
Output is correct |
24 |
Correct |
168 ms |
109148 KB |
Output is correct |
25 |
Correct |
200 ms |
109148 KB |
Output is correct |
26 |
Correct |
214 ms |
109148 KB |
Output is correct |
27 |
Correct |
183 ms |
109220 KB |
Output is correct |
28 |
Correct |
167 ms |
109220 KB |
Output is correct |
29 |
Correct |
203 ms |
110892 KB |
Output is correct |
30 |
Correct |
355 ms |
114364 KB |
Output is correct |
31 |
Correct |
524 ms |
117836 KB |
Output is correct |
32 |
Correct |
512 ms |
117836 KB |
Output is correct |
33 |
Correct |
469 ms |
117836 KB |
Output is correct |
34 |
Correct |
552 ms |
117836 KB |
Output is correct |
35 |
Correct |
613 ms |
117836 KB |
Output is correct |
36 |
Correct |
464 ms |
117852 KB |
Output is correct |
37 |
Correct |
444 ms |
117916 KB |
Output is correct |
38 |
Correct |
431 ms |
117916 KB |
Output is correct |
39 |
Correct |
446 ms |
117916 KB |
Output is correct |
40 |
Correct |
414 ms |
117936 KB |
Output is correct |
41 |
Correct |
375 ms |
117936 KB |
Output is correct |
42 |
Correct |
430 ms |
117936 KB |
Output is correct |
43 |
Correct |
457 ms |
117936 KB |
Output is correct |
44 |
Correct |
388 ms |
117936 KB |
Output is correct |
45 |
Correct |
503 ms |
117936 KB |
Output is correct |
46 |
Correct |
404 ms |
117936 KB |
Output is correct |
47 |
Incorrect |
1621 ms |
138700 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |