#include "bubblesort2.h"
#include "bits/stdc++.h"
using namespace std;
map<int,int> compress;
int n = 1;
struct segment_tree{
int t[1'000'001 * 3], lz[1'000'001 * 3];
void build(int l = 0, int r = n - 1, int k = 1){
if (l == r){
t[k] = 0;
lz[k] = 0;
return;
}
build(l,(l+r)/2,k*2);
build((l+r)/2+1,r,k*2+1);
t[k] = 0;
lz[k] = 0;
}
void push(int k, int l, int r){
t[k] += lz[k];
if (l != r){
lz[k * 2] += lz[k];
lz[k * 2 + 1] += lz[k];
}
lz[k] = 0;
}
void upd(int l, int r, int k, int L, int R, int V){
//cout << l << " " << r << " " << L << " " << R << " " << V << endl;
push(k,l,r);
if (l > R || r < L)return;
if (l >= L && r <= R){
lz[k] += V;
push(k,l,r);
return;
}
int mid = (l+r) / 2;
upd(l,mid,k*2,L,R,V);
upd(mid+1,r,k*2+1,L,R,V);
t[k] = max(t[k * 2], t[k * 2 + 1]);
}
int get(int W, int l = 0, int r = n - 1, int k = 1){
push(k,l,r);
if (l == r){
return t[k];
}
int mid = (l+r)/2;
if (W <= mid)return get(W,l,mid,k*2);
else return get(W,mid+1,r,k*2+1);
}
} st;
vector<int> countScans(vector<int> A, vector<int> X,vector<int> V){
int Q = X.size();
vector<int> answer(Q);
vector<vector<int>> AllElements;
for (int i = 0; i < (int)A.size(); i++)AllElements.push_back({A[i], i, 1});
for (int i = 0; i < (int)V.size(); i++)AllElements.push_back({V[i], i, 2});
sort(AllElements.begin(), AllElements.end());
vector<int>AI((int)A.size());
vector<int>VI((int)V.size());
for (int i = 0; i < (int)AllElements.size(); i++){
if (AllElements[i][2] == 2){
VI[AllElements[i][1]] = i;
}else{
AI[AllElements[i][1]] = i;
}
if (!i || AllElements[i][0] != AllElements[i - 1][0])compress[AllElements[i][0]] = i;
}
n = (int) AllElements.size();
st.build();
for (int i = 0; i < (int)A.size(); i++){
st.upd(0,n-1,1,compress[A[i]],n - 1, -1);
st.upd(0,n-1,1,AI[i], AI[i], i + 1);
//for (int j = 0; j < n; j++)cout << st.get(j) << ' ';
//cout << endl;
}
for (int i = 0; i < (int)X.size(); i++){
st.upd(0,n-1,1,compress[A[X[i]]], n - 1, 1);
st.upd(0,n-1,1,AI[X[i]], AI[X[i]], -X[i] - 1);
A[X[i]] = V[i];
AI[X[i]] = VI[i];
st.upd(0,n-1,1,compress[A[X[i]]],n - 1, -1);
st.upd(0,n-1,1,AI[X[i]], AI[X[i]], X[i] + 1);
//for (int j = 0; j < n; j++)cout << st.get(j) << ' ';
//cout << endl;
st.push(1,0,n-1);
answer[i] = st.t[1];
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2548 KB |
Output is correct |
3 |
Correct |
4 ms |
2908 KB |
Output is correct |
4 |
Correct |
4 ms |
2908 KB |
Output is correct |
5 |
Correct |
4 ms |
3056 KB |
Output is correct |
6 |
Correct |
4 ms |
2908 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
4 ms |
2908 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
4 ms |
3000 KB |
Output is correct |
11 |
Correct |
4 ms |
2908 KB |
Output is correct |
12 |
Correct |
4 ms |
2908 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
4 ms |
3016 KB |
Output is correct |
15 |
Correct |
4 ms |
2916 KB |
Output is correct |
16 |
Correct |
4 ms |
2908 KB |
Output is correct |
17 |
Correct |
6 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2548 KB |
Output is correct |
3 |
Correct |
4 ms |
2908 KB |
Output is correct |
4 |
Correct |
4 ms |
2908 KB |
Output is correct |
5 |
Correct |
4 ms |
3056 KB |
Output is correct |
6 |
Correct |
4 ms |
2908 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
4 ms |
2908 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
4 ms |
3000 KB |
Output is correct |
11 |
Correct |
4 ms |
2908 KB |
Output is correct |
12 |
Correct |
4 ms |
2908 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
4 ms |
3016 KB |
Output is correct |
15 |
Correct |
4 ms |
2916 KB |
Output is correct |
16 |
Correct |
4 ms |
2908 KB |
Output is correct |
17 |
Correct |
6 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2908 KB |
Output is correct |
19 |
Correct |
17 ms |
4360 KB |
Output is correct |
20 |
Correct |
18 ms |
4484 KB |
Output is correct |
21 |
Correct |
17 ms |
4504 KB |
Output is correct |
22 |
Correct |
18 ms |
4504 KB |
Output is correct |
23 |
Correct |
17 ms |
4504 KB |
Output is correct |
24 |
Correct |
17 ms |
4504 KB |
Output is correct |
25 |
Correct |
25 ms |
4504 KB |
Output is correct |
26 |
Correct |
16 ms |
4504 KB |
Output is correct |
27 |
Correct |
16 ms |
4336 KB |
Output is correct |
28 |
Correct |
17 ms |
4504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
6676 KB |
Output is correct |
2 |
Correct |
63 ms |
9488 KB |
Output is correct |
3 |
Correct |
93 ms |
14348 KB |
Output is correct |
4 |
Correct |
95 ms |
14340 KB |
Output is correct |
5 |
Correct |
86 ms |
14348 KB |
Output is correct |
6 |
Correct |
82 ms |
14560 KB |
Output is correct |
7 |
Correct |
81 ms |
14348 KB |
Output is correct |
8 |
Correct |
86 ms |
14856 KB |
Output is correct |
9 |
Correct |
87 ms |
14340 KB |
Output is correct |
10 |
Correct |
73 ms |
14596 KB |
Output is correct |
11 |
Correct |
79 ms |
14596 KB |
Output is correct |
12 |
Correct |
78 ms |
15308 KB |
Output is correct |
13 |
Correct |
77 ms |
14612 KB |
Output is correct |
14 |
Correct |
80 ms |
14596 KB |
Output is correct |
15 |
Correct |
79 ms |
14596 KB |
Output is correct |
16 |
Correct |
80 ms |
14860 KB |
Output is correct |
17 |
Correct |
77 ms |
14592 KB |
Output is correct |
18 |
Correct |
78 ms |
14596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2548 KB |
Output is correct |
3 |
Correct |
4 ms |
2908 KB |
Output is correct |
4 |
Correct |
4 ms |
2908 KB |
Output is correct |
5 |
Correct |
4 ms |
3056 KB |
Output is correct |
6 |
Correct |
4 ms |
2908 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
4 ms |
2908 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
4 ms |
3000 KB |
Output is correct |
11 |
Correct |
4 ms |
2908 KB |
Output is correct |
12 |
Correct |
4 ms |
2908 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
4 ms |
3016 KB |
Output is correct |
15 |
Correct |
4 ms |
2916 KB |
Output is correct |
16 |
Correct |
4 ms |
2908 KB |
Output is correct |
17 |
Correct |
6 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2908 KB |
Output is correct |
19 |
Correct |
17 ms |
4360 KB |
Output is correct |
20 |
Correct |
18 ms |
4484 KB |
Output is correct |
21 |
Correct |
17 ms |
4504 KB |
Output is correct |
22 |
Correct |
18 ms |
4504 KB |
Output is correct |
23 |
Correct |
17 ms |
4504 KB |
Output is correct |
24 |
Correct |
17 ms |
4504 KB |
Output is correct |
25 |
Correct |
25 ms |
4504 KB |
Output is correct |
26 |
Correct |
16 ms |
4504 KB |
Output is correct |
27 |
Correct |
16 ms |
4336 KB |
Output is correct |
28 |
Correct |
17 ms |
4504 KB |
Output is correct |
29 |
Correct |
18 ms |
6676 KB |
Output is correct |
30 |
Correct |
63 ms |
9488 KB |
Output is correct |
31 |
Correct |
93 ms |
14348 KB |
Output is correct |
32 |
Correct |
95 ms |
14340 KB |
Output is correct |
33 |
Correct |
86 ms |
14348 KB |
Output is correct |
34 |
Correct |
82 ms |
14560 KB |
Output is correct |
35 |
Correct |
81 ms |
14348 KB |
Output is correct |
36 |
Correct |
86 ms |
14856 KB |
Output is correct |
37 |
Correct |
87 ms |
14340 KB |
Output is correct |
38 |
Correct |
73 ms |
14596 KB |
Output is correct |
39 |
Correct |
79 ms |
14596 KB |
Output is correct |
40 |
Correct |
78 ms |
15308 KB |
Output is correct |
41 |
Correct |
77 ms |
14612 KB |
Output is correct |
42 |
Correct |
80 ms |
14596 KB |
Output is correct |
43 |
Correct |
79 ms |
14596 KB |
Output is correct |
44 |
Correct |
80 ms |
14860 KB |
Output is correct |
45 |
Correct |
77 ms |
14592 KB |
Output is correct |
46 |
Correct |
78 ms |
14596 KB |
Output is correct |
47 |
Correct |
491 ms |
50784 KB |
Output is correct |
48 |
Correct |
2389 ms |
141556 KB |
Output is correct |
49 |
Correct |
2563 ms |
151272 KB |
Output is correct |
50 |
Correct |
2643 ms |
151276 KB |
Output is correct |
51 |
Correct |
2659 ms |
151784 KB |
Output is correct |
52 |
Correct |
2799 ms |
152220 KB |
Output is correct |
53 |
Correct |
3172 ms |
151268 KB |
Output is correct |
54 |
Correct |
2519 ms |
149960 KB |
Output is correct |
55 |
Correct |
2599 ms |
150472 KB |
Output is correct |
56 |
Correct |
2455 ms |
150344 KB |
Output is correct |
57 |
Correct |
2666 ms |
151356 KB |
Output is correct |
58 |
Correct |
2420 ms |
151788 KB |
Output is correct |
59 |
Correct |
2017 ms |
145008 KB |
Output is correct |
60 |
Correct |
2112 ms |
144416 KB |
Output is correct |
61 |
Correct |
1926 ms |
144240 KB |
Output is correct |
62 |
Correct |
1980 ms |
142068 KB |
Output is correct |
63 |
Correct |
1876 ms |
140400 KB |
Output is correct |
64 |
Correct |
1874 ms |
142056 KB |
Output is correct |
65 |
Correct |
1643 ms |
137880 KB |
Output is correct |
66 |
Correct |
1840 ms |
139076 KB |
Output is correct |
67 |
Correct |
1855 ms |
138100 KB |
Output is correct |