#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
const int maxn = 1e6+10;
int n;
int num[maxn], qtd[maxn], soma[maxn];
int tree[4*maxn], lazy[4*maxn];
set<int> Pos[maxn];
void build(int node, int l, int r)
{
if (l == r)
{
tree[node] = -soma[l]-(*Pos[l].begin());
return;
}
int mid = (l+r)>>1;
build(2*node, l, mid); build(2*node+1, mid+1, r);
tree[node] = max(tree[2*node], tree[2*node+1]);
}
void flush(int node, int l, int r)
{
if (!lazy[node]) return;
if (l != r)
{
lazy[2*node] += lazy[node];
lazy[2*node+1] += lazy[node];
}
tree[node] += lazy[node];
lazy[node] = 0;
}
void upd(int node, int l, int r, int a, int b, int v)
{
if (l > r) return;
flush(node, l, r);
if (l > b || r < a) return;
if (l >= a && r <= b)
{
lazy[node] += v;
flush(node, l, r);
return;
}
int mid = (l+r)>>1;
upd(2*node, l, mid, a, b, v); upd(2*node+1, mid+1, r, a, b, v);
tree[node] = max(tree[2*node], tree[2*node+1]);
}
int query(int node, int l, int r, int a, int b)
{
flush(node, l, r);
if (l > b || r < a) return -1e9-10;
if (l >= a && r <= b) return tree[node];
int mid = (l+r)>>1;
return max(query(2*node, l, mid, a, b), query(2*node+1, mid+1, r, a, b));
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
n = A.size();
vector<int> C;
map<int, int> Mp;
for (int i = 0; i < n; i++) C.push_back(A[i]);
for (int i = 0; i < V.size(); i++) C.push_back(V[i]);
sort(C.begin(), C.end());
int ind = 0;
for (auto x: C)
if (Mp.find(x) == Mp.end())
Mp[x] = ++ind, Pos[ind].insert(1e9+10);
for (int i = 0; i < n; i++)
{
num[i] = Mp[A[i]];
qtd[num[i]]++;
Pos[num[i]].insert(-i);
}
for (int i = 1; i <= ind; i++)
soma[i] = soma[i-1] + qtd[i];
build(1, 1, ind);
vector<int> ans;
for (int i = 0; i < V.size(); i++)
{
int pos = X[i], v = Mp[V[i]];
upd(1, 1, ind, num[pos], ind, 1);
bool last = 0;
if (pos == -(*Pos[num[pos]].begin())) last = 1;
Pos[num[pos]].erase(-pos);
if (last) upd(1, 1, ind, num[pos], num[pos], -(*Pos[num[pos]].begin())-pos);
num[pos] = v;
upd(1, 1, ind, v, v, *Pos[v].begin());
Pos[v].insert(-pos);
upd(1, 1, ind, v, ind, -1);
upd(1, 1, ind, v, v, -(*Pos[v].begin()));
ans.push_back(1+query(1, 1, ind, 1, ind));
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:86:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < V.size(); i++) C.push_back(V[i]);
~~^~~~~~~~~~
bubblesort2.cpp:110:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < V.size(); i++)
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
47480 KB |
Output is correct |
2 |
Correct |
46 ms |
47616 KB |
Output is correct |
3 |
Correct |
60 ms |
47992 KB |
Output is correct |
4 |
Correct |
58 ms |
47992 KB |
Output is correct |
5 |
Correct |
48 ms |
48000 KB |
Output is correct |
6 |
Correct |
47 ms |
47992 KB |
Output is correct |
7 |
Correct |
56 ms |
48120 KB |
Output is correct |
8 |
Correct |
59 ms |
47992 KB |
Output is correct |
9 |
Correct |
49 ms |
47992 KB |
Output is correct |
10 |
Correct |
49 ms |
47992 KB |
Output is correct |
11 |
Correct |
48 ms |
47964 KB |
Output is correct |
12 |
Correct |
50 ms |
47992 KB |
Output is correct |
13 |
Correct |
50 ms |
47992 KB |
Output is correct |
14 |
Correct |
49 ms |
47864 KB |
Output is correct |
15 |
Correct |
50 ms |
47896 KB |
Output is correct |
16 |
Correct |
49 ms |
47872 KB |
Output is correct |
17 |
Correct |
53 ms |
47880 KB |
Output is correct |
18 |
Correct |
50 ms |
47992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
47480 KB |
Output is correct |
2 |
Correct |
46 ms |
47616 KB |
Output is correct |
3 |
Correct |
60 ms |
47992 KB |
Output is correct |
4 |
Correct |
58 ms |
47992 KB |
Output is correct |
5 |
Correct |
48 ms |
48000 KB |
Output is correct |
6 |
Correct |
47 ms |
47992 KB |
Output is correct |
7 |
Correct |
56 ms |
48120 KB |
Output is correct |
8 |
Correct |
59 ms |
47992 KB |
Output is correct |
9 |
Correct |
49 ms |
47992 KB |
Output is correct |
10 |
Correct |
49 ms |
47992 KB |
Output is correct |
11 |
Correct |
48 ms |
47964 KB |
Output is correct |
12 |
Correct |
50 ms |
47992 KB |
Output is correct |
13 |
Correct |
50 ms |
47992 KB |
Output is correct |
14 |
Correct |
49 ms |
47864 KB |
Output is correct |
15 |
Correct |
50 ms |
47896 KB |
Output is correct |
16 |
Correct |
49 ms |
47872 KB |
Output is correct |
17 |
Correct |
53 ms |
47880 KB |
Output is correct |
18 |
Correct |
50 ms |
47992 KB |
Output is correct |
19 |
Correct |
75 ms |
49656 KB |
Output is correct |
20 |
Correct |
84 ms |
50012 KB |
Output is correct |
21 |
Correct |
75 ms |
49912 KB |
Output is correct |
22 |
Correct |
89 ms |
50040 KB |
Output is correct |
23 |
Correct |
73 ms |
49784 KB |
Output is correct |
24 |
Correct |
73 ms |
49784 KB |
Output is correct |
25 |
Correct |
82 ms |
49656 KB |
Output is correct |
26 |
Correct |
76 ms |
49656 KB |
Output is correct |
27 |
Correct |
69 ms |
49528 KB |
Output is correct |
28 |
Correct |
71 ms |
49528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
49144 KB |
Output is correct |
2 |
Correct |
112 ms |
51040 KB |
Output is correct |
3 |
Correct |
186 ms |
52520 KB |
Output is correct |
4 |
Correct |
182 ms |
52424 KB |
Output is correct |
5 |
Correct |
175 ms |
52436 KB |
Output is correct |
6 |
Correct |
181 ms |
52492 KB |
Output is correct |
7 |
Correct |
145 ms |
52464 KB |
Output is correct |
8 |
Correct |
174 ms |
52468 KB |
Output is correct |
9 |
Correct |
179 ms |
52464 KB |
Output is correct |
10 |
Correct |
145 ms |
52680 KB |
Output is correct |
11 |
Correct |
142 ms |
52592 KB |
Output is correct |
12 |
Correct |
136 ms |
52692 KB |
Output is correct |
13 |
Correct |
124 ms |
52596 KB |
Output is correct |
14 |
Correct |
124 ms |
52592 KB |
Output is correct |
15 |
Correct |
136 ms |
52636 KB |
Output is correct |
16 |
Correct |
111 ms |
52592 KB |
Output is correct |
17 |
Correct |
120 ms |
52564 KB |
Output is correct |
18 |
Correct |
138 ms |
52564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
47480 KB |
Output is correct |
2 |
Correct |
46 ms |
47616 KB |
Output is correct |
3 |
Correct |
60 ms |
47992 KB |
Output is correct |
4 |
Correct |
58 ms |
47992 KB |
Output is correct |
5 |
Correct |
48 ms |
48000 KB |
Output is correct |
6 |
Correct |
47 ms |
47992 KB |
Output is correct |
7 |
Correct |
56 ms |
48120 KB |
Output is correct |
8 |
Correct |
59 ms |
47992 KB |
Output is correct |
9 |
Correct |
49 ms |
47992 KB |
Output is correct |
10 |
Correct |
49 ms |
47992 KB |
Output is correct |
11 |
Correct |
48 ms |
47964 KB |
Output is correct |
12 |
Correct |
50 ms |
47992 KB |
Output is correct |
13 |
Correct |
50 ms |
47992 KB |
Output is correct |
14 |
Correct |
49 ms |
47864 KB |
Output is correct |
15 |
Correct |
50 ms |
47896 KB |
Output is correct |
16 |
Correct |
49 ms |
47872 KB |
Output is correct |
17 |
Correct |
53 ms |
47880 KB |
Output is correct |
18 |
Correct |
50 ms |
47992 KB |
Output is correct |
19 |
Correct |
75 ms |
49656 KB |
Output is correct |
20 |
Correct |
84 ms |
50012 KB |
Output is correct |
21 |
Correct |
75 ms |
49912 KB |
Output is correct |
22 |
Correct |
89 ms |
50040 KB |
Output is correct |
23 |
Correct |
73 ms |
49784 KB |
Output is correct |
24 |
Correct |
73 ms |
49784 KB |
Output is correct |
25 |
Correct |
82 ms |
49656 KB |
Output is correct |
26 |
Correct |
76 ms |
49656 KB |
Output is correct |
27 |
Correct |
69 ms |
49528 KB |
Output is correct |
28 |
Correct |
71 ms |
49528 KB |
Output is correct |
29 |
Correct |
63 ms |
49144 KB |
Output is correct |
30 |
Correct |
112 ms |
51040 KB |
Output is correct |
31 |
Correct |
186 ms |
52520 KB |
Output is correct |
32 |
Correct |
182 ms |
52424 KB |
Output is correct |
33 |
Correct |
175 ms |
52436 KB |
Output is correct |
34 |
Correct |
181 ms |
52492 KB |
Output is correct |
35 |
Correct |
145 ms |
52464 KB |
Output is correct |
36 |
Correct |
174 ms |
52468 KB |
Output is correct |
37 |
Correct |
179 ms |
52464 KB |
Output is correct |
38 |
Correct |
145 ms |
52680 KB |
Output is correct |
39 |
Correct |
142 ms |
52592 KB |
Output is correct |
40 |
Correct |
136 ms |
52692 KB |
Output is correct |
41 |
Correct |
124 ms |
52596 KB |
Output is correct |
42 |
Correct |
124 ms |
52592 KB |
Output is correct |
43 |
Correct |
136 ms |
52636 KB |
Output is correct |
44 |
Correct |
111 ms |
52592 KB |
Output is correct |
45 |
Correct |
120 ms |
52564 KB |
Output is correct |
46 |
Correct |
138 ms |
52564 KB |
Output is correct |
47 |
Correct |
1397 ms |
102552 KB |
Output is correct |
48 |
Correct |
5166 ms |
201736 KB |
Output is correct |
49 |
Correct |
5854 ms |
215504 KB |
Output is correct |
50 |
Correct |
5511 ms |
215844 KB |
Output is correct |
51 |
Correct |
5589 ms |
215700 KB |
Output is correct |
52 |
Correct |
5433 ms |
215700 KB |
Output is correct |
53 |
Correct |
5377 ms |
215844 KB |
Output is correct |
54 |
Correct |
5018 ms |
215584 KB |
Output is correct |
55 |
Correct |
4769 ms |
215512 KB |
Output is correct |
56 |
Correct |
4808 ms |
215564 KB |
Output is correct |
57 |
Correct |
5136 ms |
215728 KB |
Output is correct |
58 |
Correct |
4433 ms |
215680 KB |
Output is correct |
59 |
Correct |
4113 ms |
203116 KB |
Output is correct |
60 |
Correct |
4260 ms |
203052 KB |
Output is correct |
61 |
Correct |
4300 ms |
203040 KB |
Output is correct |
62 |
Correct |
3984 ms |
196624 KB |
Output is correct |
63 |
Correct |
4232 ms |
196660 KB |
Output is correct |
64 |
Correct |
4103 ms |
196732 KB |
Output is correct |
65 |
Correct |
4134 ms |
190196 KB |
Output is correct |
66 |
Correct |
3845 ms |
190496 KB |
Output is correct |
67 |
Correct |
3678 ms |
190564 KB |
Output is correct |