#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
int seg[4000005], lazy[4000005];
vector<pair<int, int> > vec;
vector<int> ans;
void push(int i, int l, int r)
{
if (l==r)
{
seg[i]+=lazy[i];
lazy[i]=0;
return;
}
seg[i]+=lazy[i];
lazy[i*2]+=lazy[i];
lazy[i*2+1]+=lazy[i];
lazy[i]=0;
}
void upd(int i, int l, int r, int ql, int qr, int val)
{
if (ql<=l && r<=qr)
{
lazy[i]+=val;
push(i, l, r);
return;
}
int mid=(l+r)/2;
push(i*2, l, mid);
push(i*2+1, mid+1, r);
if (ql<=mid && l<=qr)
upd(i*2, l, mid, ql, qr, val);
if (ql<=r && mid+1<=qr)
upd(i*2+1, mid+1, r, ql, qr, val);
seg[i]=max(seg[i*2], seg[i*2+1]);
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> y)
{
int n=a.size(), m=x.size();
for (int i=0; i<n; i++)
vec.push_back({a[i], i});
for (int i=0; i<m; i++)
vec.push_back({y[i], x[i]});
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
int sz=vec.size();
for (int i=0; i<n; i++)
{
int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[i], i))-vec.begin();
int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[i], 0))-vec.begin();
upd(1, 0, sz-1, ind, ind, i+1);
upd(1, 0, sz-1, ind2, sz-1, -1);
}
for (int i=0; i<m; i++)
{
int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], 0))-vec.begin();
upd(1, 0, sz-1, ind, ind, -x[i]-1);
upd(1, 0, sz-1, ind2, sz-1, 1);
a[x[i]]=y[i];
ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], 0))-vec.begin();
upd(1, 0, sz-1, ind, ind, x[i]+1);
upd(1, 0, sz-1, ind2, sz-1, -1);
ans.push_back(seg[1]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
488 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
496 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
488 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
496 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
17 ms |
992 KB |
Output is correct |
20 |
Correct |
18 ms |
980 KB |
Output is correct |
21 |
Correct |
19 ms |
1028 KB |
Output is correct |
22 |
Correct |
19 ms |
1048 KB |
Output is correct |
23 |
Correct |
18 ms |
980 KB |
Output is correct |
24 |
Correct |
24 ms |
1032 KB |
Output is correct |
25 |
Correct |
20 ms |
1032 KB |
Output is correct |
26 |
Correct |
17 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
980 KB |
Output is correct |
28 |
Correct |
18 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1440 KB |
Output is correct |
2 |
Correct |
104 ms |
2740 KB |
Output is correct |
3 |
Correct |
143 ms |
4764 KB |
Output is correct |
4 |
Correct |
149 ms |
4832 KB |
Output is correct |
5 |
Correct |
166 ms |
4764 KB |
Output is correct |
6 |
Correct |
156 ms |
4672 KB |
Output is correct |
7 |
Correct |
136 ms |
4724 KB |
Output is correct |
8 |
Correct |
143 ms |
4768 KB |
Output is correct |
9 |
Correct |
141 ms |
4780 KB |
Output is correct |
10 |
Correct |
104 ms |
3684 KB |
Output is correct |
11 |
Correct |
134 ms |
3704 KB |
Output is correct |
12 |
Correct |
112 ms |
3796 KB |
Output is correct |
13 |
Correct |
107 ms |
3748 KB |
Output is correct |
14 |
Correct |
109 ms |
3844 KB |
Output is correct |
15 |
Correct |
103 ms |
3688 KB |
Output is correct |
16 |
Correct |
116 ms |
3720 KB |
Output is correct |
17 |
Correct |
120 ms |
3716 KB |
Output is correct |
18 |
Correct |
108 ms |
3648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
488 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
496 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
17 ms |
992 KB |
Output is correct |
20 |
Correct |
18 ms |
980 KB |
Output is correct |
21 |
Correct |
19 ms |
1028 KB |
Output is correct |
22 |
Correct |
19 ms |
1048 KB |
Output is correct |
23 |
Correct |
18 ms |
980 KB |
Output is correct |
24 |
Correct |
24 ms |
1032 KB |
Output is correct |
25 |
Correct |
20 ms |
1032 KB |
Output is correct |
26 |
Correct |
17 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
980 KB |
Output is correct |
28 |
Correct |
18 ms |
980 KB |
Output is correct |
29 |
Correct |
26 ms |
1440 KB |
Output is correct |
30 |
Correct |
104 ms |
2740 KB |
Output is correct |
31 |
Correct |
143 ms |
4764 KB |
Output is correct |
32 |
Correct |
149 ms |
4832 KB |
Output is correct |
33 |
Correct |
166 ms |
4764 KB |
Output is correct |
34 |
Correct |
156 ms |
4672 KB |
Output is correct |
35 |
Correct |
136 ms |
4724 KB |
Output is correct |
36 |
Correct |
143 ms |
4768 KB |
Output is correct |
37 |
Correct |
141 ms |
4780 KB |
Output is correct |
38 |
Correct |
104 ms |
3684 KB |
Output is correct |
39 |
Correct |
134 ms |
3704 KB |
Output is correct |
40 |
Correct |
112 ms |
3796 KB |
Output is correct |
41 |
Correct |
107 ms |
3748 KB |
Output is correct |
42 |
Correct |
109 ms |
3844 KB |
Output is correct |
43 |
Correct |
103 ms |
3688 KB |
Output is correct |
44 |
Correct |
116 ms |
3720 KB |
Output is correct |
45 |
Correct |
120 ms |
3716 KB |
Output is correct |
46 |
Correct |
108 ms |
3648 KB |
Output is correct |
47 |
Correct |
513 ms |
15780 KB |
Output is correct |
48 |
Correct |
2122 ms |
38704 KB |
Output is correct |
49 |
Correct |
2308 ms |
40428 KB |
Output is correct |
50 |
Correct |
2282 ms |
40288 KB |
Output is correct |
51 |
Correct |
2244 ms |
40292 KB |
Output is correct |
52 |
Correct |
2205 ms |
40284 KB |
Output is correct |
53 |
Correct |
2200 ms |
40316 KB |
Output is correct |
54 |
Correct |
1977 ms |
40304 KB |
Output is correct |
55 |
Correct |
2133 ms |
40288 KB |
Output is correct |
56 |
Correct |
1952 ms |
40404 KB |
Output is correct |
57 |
Correct |
2061 ms |
40376 KB |
Output is correct |
58 |
Correct |
1997 ms |
40312 KB |
Output is correct |
59 |
Correct |
1839 ms |
40304 KB |
Output is correct |
60 |
Correct |
1896 ms |
40316 KB |
Output is correct |
61 |
Correct |
1869 ms |
40368 KB |
Output is correct |
62 |
Correct |
1774 ms |
40468 KB |
Output is correct |
63 |
Correct |
1897 ms |
40476 KB |
Output is correct |
64 |
Correct |
1838 ms |
40444 KB |
Output is correct |
65 |
Correct |
1714 ms |
40356 KB |
Output is correct |
66 |
Correct |
1641 ms |
40596 KB |
Output is correct |
67 |
Correct |
1617 ms |
40352 KB |
Output is correct |