//https://oj.uz/problem/view/JOI18_bubblesort2
#include "bubblesort2.h"
#include<bits/stdc++.h>
const int N = 1e5 + 5;
const int MAX = 1e6 + 5;
const int inf = 1e9;
using namespace std;
map <int, int> mp;
typedef vector <int> vi;
multiset <int> ms[MAX];
int n, q, cnt, it[MAX << 2], lazy[MAX << 2], bit[MAX], offset[MAX];
void updateBIT(int i, int v){
while (i < MAX){
bit[i] += v;
i += i&(-i);
}
}
int getBIT(int i){
int ans = 0;
while (i > 0){
ans += bit[i];
i -= i&(-i);
}
return ans;
}
void dolazy(int i, int l, int r){
if (!lazy[i]) return;
if (l != r){
lazy[i << 1] += lazy[i];
lazy[i << 1 | 1] += lazy[i];
}
else{
offset[l] += lazy[i];
}
it[i] += lazy[i];
lazy[i] = 0;
}
void Insert(int i, int l, int r, int pos, int val){
dolazy(i, l, r);
if (l > pos || pos > r) return;
if (l == r){
ms[l].insert(val - offset[l]);
if (ms[l].size()) it[i] = *ms[l].rbegin() + offset[l];
else it[i] = -inf;
return;
}
int mid = (l + r) >> 1;
Insert(i << 1, l, mid, pos, val); Insert(i << 1 | 1, mid+1, r, pos, val);
it[i] = max(it[i << 1], it[i << 1 | 1]);
}
void Erase(int i, int l, int r, int pos, int val){
dolazy(i, l, r);
if (l > pos || pos > r) return;
if (l == r){
ms[l].erase(ms[l].lower_bound(val - offset[l]));
if (ms[l].size()) it[i] = *ms[l].rbegin() + offset[l];
else it[i] = -inf;
return;
}
int mid = (l + r) >> 1;
Erase(i << 1, l, mid, pos, val); Erase(i << 1 | 1, mid+1, r, pos, val);
it[i] = max(it[i << 1], it[i << 1 | 1]);
}
void update(int i, int l, int r, int L, int R, int v){
dolazy(i, l, r);
if (L > r || l > R) return;
if (L <= l && r <= R){
lazy[i] = v;
dolazy(i, l, r);
return;
}
int mid = (l + r) >> 1;
update(i << 1, l, mid, L, R, v); update(i << 1 | 1, mid+1, r, L, R, v);
it[i] = max(it[i << 1], it[i << 1 | 1]);
}
vi countScans(vi a, vi x, vi y){
n = a.size(), q = x.size();
vi ans(q);
for (auto val : a) mp[val] = true;
for (auto val : y) mp[val] = true;
for (auto& p : mp) p.second = ++cnt;
for (auto& val : a) val = mp[val], updateBIT(val, +1);
for (auto& val : y) val = mp[val];
for (int i = 0; i < MAX << 2; i++) it[i] = -inf;
for (int i = 0; i < n; i++) Insert(1, 1, cnt, a[i], i+1-getBIT(a[i]));
for (int i = 0; i < q; i++){
Erase(1, 1, cnt, a[x[i]], x[i]+1-getBIT(a[x[i]]));
update(1, 1, cnt, a[x[i]], cnt, +1);
updateBIT(a[x[i]], -1);
a[x[i]] = y[i];
updateBIT(a[x[i]], +1);
update(1, 1, cnt, a[x[i]], cnt, -1);
Insert(1, 1, cnt, a[x[i]], x[i]+1-getBIT(a[x[i]]));
ans[i] = it[1];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
63096 KB |
Output is correct |
2 |
Correct |
60 ms |
63224 KB |
Output is correct |
3 |
Correct |
67 ms |
63352 KB |
Output is correct |
4 |
Correct |
70 ms |
63480 KB |
Output is correct |
5 |
Correct |
70 ms |
63352 KB |
Output is correct |
6 |
Correct |
77 ms |
63352 KB |
Output is correct |
7 |
Correct |
69 ms |
63432 KB |
Output is correct |
8 |
Correct |
65 ms |
63352 KB |
Output is correct |
9 |
Correct |
66 ms |
63352 KB |
Output is correct |
10 |
Correct |
65 ms |
63480 KB |
Output is correct |
11 |
Correct |
70 ms |
63480 KB |
Output is correct |
12 |
Correct |
65 ms |
63352 KB |
Output is correct |
13 |
Correct |
66 ms |
63480 KB |
Output is correct |
14 |
Correct |
62 ms |
63324 KB |
Output is correct |
15 |
Correct |
69 ms |
63372 KB |
Output is correct |
16 |
Correct |
68 ms |
63384 KB |
Output is correct |
17 |
Correct |
69 ms |
63352 KB |
Output is correct |
18 |
Correct |
69 ms |
63480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
63096 KB |
Output is correct |
2 |
Correct |
60 ms |
63224 KB |
Output is correct |
3 |
Correct |
67 ms |
63352 KB |
Output is correct |
4 |
Correct |
70 ms |
63480 KB |
Output is correct |
5 |
Correct |
70 ms |
63352 KB |
Output is correct |
6 |
Correct |
77 ms |
63352 KB |
Output is correct |
7 |
Correct |
69 ms |
63432 KB |
Output is correct |
8 |
Correct |
65 ms |
63352 KB |
Output is correct |
9 |
Correct |
66 ms |
63352 KB |
Output is correct |
10 |
Correct |
65 ms |
63480 KB |
Output is correct |
11 |
Correct |
70 ms |
63480 KB |
Output is correct |
12 |
Correct |
65 ms |
63352 KB |
Output is correct |
13 |
Correct |
66 ms |
63480 KB |
Output is correct |
14 |
Correct |
62 ms |
63324 KB |
Output is correct |
15 |
Correct |
69 ms |
63372 KB |
Output is correct |
16 |
Correct |
68 ms |
63384 KB |
Output is correct |
17 |
Correct |
69 ms |
63352 KB |
Output is correct |
18 |
Correct |
69 ms |
63480 KB |
Output is correct |
19 |
Correct |
80 ms |
64504 KB |
Output is correct |
20 |
Correct |
99 ms |
64664 KB |
Output is correct |
21 |
Correct |
99 ms |
64760 KB |
Output is correct |
22 |
Correct |
92 ms |
64760 KB |
Output is correct |
23 |
Correct |
91 ms |
64504 KB |
Output is correct |
24 |
Correct |
86 ms |
64636 KB |
Output is correct |
25 |
Correct |
81 ms |
64504 KB |
Output is correct |
26 |
Correct |
85 ms |
64440 KB |
Output is correct |
27 |
Correct |
100 ms |
64376 KB |
Output is correct |
28 |
Correct |
80 ms |
64376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
64496 KB |
Output is correct |
2 |
Correct |
142 ms |
65808 KB |
Output is correct |
3 |
Correct |
208 ms |
66936 KB |
Output is correct |
4 |
Correct |
216 ms |
67320 KB |
Output is correct |
5 |
Correct |
268 ms |
67420 KB |
Output is correct |
6 |
Correct |
221 ms |
67448 KB |
Output is correct |
7 |
Correct |
240 ms |
67324 KB |
Output is correct |
8 |
Correct |
208 ms |
67352 KB |
Output is correct |
9 |
Correct |
227 ms |
67576 KB |
Output is correct |
10 |
Correct |
166 ms |
67436 KB |
Output is correct |
11 |
Correct |
155 ms |
67448 KB |
Output is correct |
12 |
Correct |
172 ms |
67468 KB |
Output is correct |
13 |
Correct |
170 ms |
67476 KB |
Output is correct |
14 |
Correct |
157 ms |
67484 KB |
Output is correct |
15 |
Correct |
148 ms |
67320 KB |
Output is correct |
16 |
Correct |
148 ms |
67320 KB |
Output is correct |
17 |
Correct |
143 ms |
67420 KB |
Output is correct |
18 |
Correct |
149 ms |
67448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
63096 KB |
Output is correct |
2 |
Correct |
60 ms |
63224 KB |
Output is correct |
3 |
Correct |
67 ms |
63352 KB |
Output is correct |
4 |
Correct |
70 ms |
63480 KB |
Output is correct |
5 |
Correct |
70 ms |
63352 KB |
Output is correct |
6 |
Correct |
77 ms |
63352 KB |
Output is correct |
7 |
Correct |
69 ms |
63432 KB |
Output is correct |
8 |
Correct |
65 ms |
63352 KB |
Output is correct |
9 |
Correct |
66 ms |
63352 KB |
Output is correct |
10 |
Correct |
65 ms |
63480 KB |
Output is correct |
11 |
Correct |
70 ms |
63480 KB |
Output is correct |
12 |
Correct |
65 ms |
63352 KB |
Output is correct |
13 |
Correct |
66 ms |
63480 KB |
Output is correct |
14 |
Correct |
62 ms |
63324 KB |
Output is correct |
15 |
Correct |
69 ms |
63372 KB |
Output is correct |
16 |
Correct |
68 ms |
63384 KB |
Output is correct |
17 |
Correct |
69 ms |
63352 KB |
Output is correct |
18 |
Correct |
69 ms |
63480 KB |
Output is correct |
19 |
Correct |
80 ms |
64504 KB |
Output is correct |
20 |
Correct |
99 ms |
64664 KB |
Output is correct |
21 |
Correct |
99 ms |
64760 KB |
Output is correct |
22 |
Correct |
92 ms |
64760 KB |
Output is correct |
23 |
Correct |
91 ms |
64504 KB |
Output is correct |
24 |
Correct |
86 ms |
64636 KB |
Output is correct |
25 |
Correct |
81 ms |
64504 KB |
Output is correct |
26 |
Correct |
85 ms |
64440 KB |
Output is correct |
27 |
Correct |
100 ms |
64376 KB |
Output is correct |
28 |
Correct |
80 ms |
64376 KB |
Output is correct |
29 |
Correct |
84 ms |
64496 KB |
Output is correct |
30 |
Correct |
142 ms |
65808 KB |
Output is correct |
31 |
Correct |
208 ms |
66936 KB |
Output is correct |
32 |
Correct |
216 ms |
67320 KB |
Output is correct |
33 |
Correct |
268 ms |
67420 KB |
Output is correct |
34 |
Correct |
221 ms |
67448 KB |
Output is correct |
35 |
Correct |
240 ms |
67324 KB |
Output is correct |
36 |
Correct |
208 ms |
67352 KB |
Output is correct |
37 |
Correct |
227 ms |
67576 KB |
Output is correct |
38 |
Correct |
166 ms |
67436 KB |
Output is correct |
39 |
Correct |
155 ms |
67448 KB |
Output is correct |
40 |
Correct |
172 ms |
67468 KB |
Output is correct |
41 |
Correct |
170 ms |
67476 KB |
Output is correct |
42 |
Correct |
157 ms |
67484 KB |
Output is correct |
43 |
Correct |
148 ms |
67320 KB |
Output is correct |
44 |
Correct |
148 ms |
67320 KB |
Output is correct |
45 |
Correct |
143 ms |
67420 KB |
Output is correct |
46 |
Correct |
149 ms |
67448 KB |
Output is correct |
47 |
Correct |
1401 ms |
98564 KB |
Output is correct |
48 |
Correct |
5880 ms |
165552 KB |
Output is correct |
49 |
Correct |
6729 ms |
173664 KB |
Output is correct |
50 |
Correct |
6437 ms |
173560 KB |
Output is correct |
51 |
Correct |
6385 ms |
173432 KB |
Output is correct |
52 |
Correct |
6677 ms |
173628 KB |
Output is correct |
53 |
Correct |
6756 ms |
173612 KB |
Output is correct |
54 |
Correct |
5541 ms |
173624 KB |
Output is correct |
55 |
Correct |
6378 ms |
173512 KB |
Output is correct |
56 |
Correct |
5380 ms |
173468 KB |
Output is correct |
57 |
Correct |
6649 ms |
173576 KB |
Output is correct |
58 |
Correct |
5700 ms |
173624 KB |
Output is correct |
59 |
Correct |
4708 ms |
166608 KB |
Output is correct |
60 |
Correct |
5131 ms |
166756 KB |
Output is correct |
61 |
Correct |
4879 ms |
166832 KB |
Output is correct |
62 |
Correct |
4986 ms |
163364 KB |
Output is correct |
63 |
Correct |
4701 ms |
163292 KB |
Output is correct |
64 |
Correct |
4342 ms |
163216 KB |
Output is correct |
65 |
Correct |
4694 ms |
159812 KB |
Output is correct |
66 |
Correct |
4375 ms |
159712 KB |
Output is correct |
67 |
Correct |
4843 ms |
159860 KB |
Output is correct |