#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__);
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 5e5 + 10;
int n, q, sz, seg[maxn << 3], lazy[maxn << 3];
vector<int> num;
set<int> idx[maxn << 1];
void shift(int v, int l, int r);
void add(int v, int l, int r, int ql, int qr, int val){
if (qr <= l || r <= ql) return;
if (ql <= l && r <= qr){
seg[v] += val;
lazy[v] += val;
return;
}
shift(v, l, r);
int mid = (l + r)>> 1;
add(v << 1, l, mid, ql, qr, val);
add(v << 1 | 1, mid, r, ql, qr, val);
seg[v] = max(seg[v << 1], seg[v << 1 | 1]);
}
void shift(int v, int l, int r){
if (lazy[v] == 0) return;
int mid = (l+r) >> 1;
add(v << 1, l, mid, l, mid, lazy[v]);
add(v << 1 | 1, mid, r, mid, r, lazy[v]);
lazy[v] = 0;
}
void add(int x, int y){
auto it = idx[y].end();
it--;
if (x > *it) add(1, 0, sz, y, y+1, x-(*it));
add(1, 0, sz, y, sz, -1);
idx[y].insert(x);
}
void remove(int x, int y){
idx[y].erase(x);
add(1, 0, sz, y, sz, 1);
auto it = idx[y].end();
it--;
if (x > *it) add(1, 0, sz, y, y+1, -x+(*it));
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
n = A.size();
q = X.size();
for (int i = 0; i < n; i++) num.push_back(A[i]);
for (int i = 0; i < q; i++) num.push_back(V[i]);
sort(all(num));
num.resize(distance(num.begin(), unique(all(num))));
sz = num.size();
for (int i = 0; i < sz; i++) idx[i].insert(0);
for (int i = 0; i < n; i++){
A[i] = lower_bound(all(num), A[i]) - num.begin();
add(i+1, A[i]);
}
vector<int> ans;
for (int i = 0; i < q; i++){
V[i] = lower_bound(all(num), V[i]) - num.begin();
remove(X[i]+1, A[X[i]]);
A[X[i]] = V[i];
add(X[i]+1, A[X[i]]);
ans.push_back(max(0, seg[1]));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47444 KB |
Output is correct |
3 |
Correct |
25 ms |
47628 KB |
Output is correct |
4 |
Correct |
25 ms |
47648 KB |
Output is correct |
5 |
Correct |
25 ms |
47644 KB |
Output is correct |
6 |
Correct |
26 ms |
47700 KB |
Output is correct |
7 |
Correct |
25 ms |
47660 KB |
Output is correct |
8 |
Correct |
26 ms |
47644 KB |
Output is correct |
9 |
Correct |
25 ms |
47736 KB |
Output is correct |
10 |
Correct |
26 ms |
47596 KB |
Output is correct |
11 |
Correct |
25 ms |
47604 KB |
Output is correct |
12 |
Correct |
25 ms |
47688 KB |
Output is correct |
13 |
Correct |
28 ms |
47784 KB |
Output is correct |
14 |
Correct |
30 ms |
47692 KB |
Output is correct |
15 |
Correct |
26 ms |
47716 KB |
Output is correct |
16 |
Correct |
25 ms |
47616 KB |
Output is correct |
17 |
Correct |
30 ms |
47660 KB |
Output is correct |
18 |
Correct |
26 ms |
47640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47444 KB |
Output is correct |
3 |
Correct |
25 ms |
47628 KB |
Output is correct |
4 |
Correct |
25 ms |
47648 KB |
Output is correct |
5 |
Correct |
25 ms |
47644 KB |
Output is correct |
6 |
Correct |
26 ms |
47700 KB |
Output is correct |
7 |
Correct |
25 ms |
47660 KB |
Output is correct |
8 |
Correct |
26 ms |
47644 KB |
Output is correct |
9 |
Correct |
25 ms |
47736 KB |
Output is correct |
10 |
Correct |
26 ms |
47596 KB |
Output is correct |
11 |
Correct |
25 ms |
47604 KB |
Output is correct |
12 |
Correct |
25 ms |
47688 KB |
Output is correct |
13 |
Correct |
28 ms |
47784 KB |
Output is correct |
14 |
Correct |
30 ms |
47692 KB |
Output is correct |
15 |
Correct |
26 ms |
47716 KB |
Output is correct |
16 |
Correct |
25 ms |
47616 KB |
Output is correct |
17 |
Correct |
30 ms |
47660 KB |
Output is correct |
18 |
Correct |
26 ms |
47640 KB |
Output is correct |
19 |
Correct |
39 ms |
48948 KB |
Output is correct |
20 |
Correct |
40 ms |
49100 KB |
Output is correct |
21 |
Correct |
39 ms |
49160 KB |
Output is correct |
22 |
Correct |
40 ms |
49176 KB |
Output is correct |
23 |
Correct |
39 ms |
49032 KB |
Output is correct |
24 |
Correct |
39 ms |
49020 KB |
Output is correct |
25 |
Correct |
38 ms |
48980 KB |
Output is correct |
26 |
Correct |
38 ms |
48936 KB |
Output is correct |
27 |
Correct |
37 ms |
48964 KB |
Output is correct |
28 |
Correct |
37 ms |
48920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
48988 KB |
Output is correct |
2 |
Correct |
63 ms |
50620 KB |
Output is correct |
3 |
Correct |
91 ms |
52352 KB |
Output is correct |
4 |
Correct |
94 ms |
52152 KB |
Output is correct |
5 |
Correct |
86 ms |
52164 KB |
Output is correct |
6 |
Correct |
86 ms |
52128 KB |
Output is correct |
7 |
Correct |
85 ms |
52232 KB |
Output is correct |
8 |
Correct |
104 ms |
52256 KB |
Output is correct |
9 |
Correct |
89 ms |
52136 KB |
Output is correct |
10 |
Correct |
75 ms |
52308 KB |
Output is correct |
11 |
Correct |
75 ms |
52224 KB |
Output is correct |
12 |
Correct |
77 ms |
52292 KB |
Output is correct |
13 |
Correct |
73 ms |
52240 KB |
Output is correct |
14 |
Correct |
74 ms |
52168 KB |
Output is correct |
15 |
Correct |
73 ms |
52168 KB |
Output is correct |
16 |
Correct |
71 ms |
52204 KB |
Output is correct |
17 |
Correct |
71 ms |
52284 KB |
Output is correct |
18 |
Correct |
71 ms |
52224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47444 KB |
Output is correct |
3 |
Correct |
25 ms |
47628 KB |
Output is correct |
4 |
Correct |
25 ms |
47648 KB |
Output is correct |
5 |
Correct |
25 ms |
47644 KB |
Output is correct |
6 |
Correct |
26 ms |
47700 KB |
Output is correct |
7 |
Correct |
25 ms |
47660 KB |
Output is correct |
8 |
Correct |
26 ms |
47644 KB |
Output is correct |
9 |
Correct |
25 ms |
47736 KB |
Output is correct |
10 |
Correct |
26 ms |
47596 KB |
Output is correct |
11 |
Correct |
25 ms |
47604 KB |
Output is correct |
12 |
Correct |
25 ms |
47688 KB |
Output is correct |
13 |
Correct |
28 ms |
47784 KB |
Output is correct |
14 |
Correct |
30 ms |
47692 KB |
Output is correct |
15 |
Correct |
26 ms |
47716 KB |
Output is correct |
16 |
Correct |
25 ms |
47616 KB |
Output is correct |
17 |
Correct |
30 ms |
47660 KB |
Output is correct |
18 |
Correct |
26 ms |
47640 KB |
Output is correct |
19 |
Correct |
39 ms |
48948 KB |
Output is correct |
20 |
Correct |
40 ms |
49100 KB |
Output is correct |
21 |
Correct |
39 ms |
49160 KB |
Output is correct |
22 |
Correct |
40 ms |
49176 KB |
Output is correct |
23 |
Correct |
39 ms |
49032 KB |
Output is correct |
24 |
Correct |
39 ms |
49020 KB |
Output is correct |
25 |
Correct |
38 ms |
48980 KB |
Output is correct |
26 |
Correct |
38 ms |
48936 KB |
Output is correct |
27 |
Correct |
37 ms |
48964 KB |
Output is correct |
28 |
Correct |
37 ms |
48920 KB |
Output is correct |
29 |
Correct |
37 ms |
48988 KB |
Output is correct |
30 |
Correct |
63 ms |
50620 KB |
Output is correct |
31 |
Correct |
91 ms |
52352 KB |
Output is correct |
32 |
Correct |
94 ms |
52152 KB |
Output is correct |
33 |
Correct |
86 ms |
52164 KB |
Output is correct |
34 |
Correct |
86 ms |
52128 KB |
Output is correct |
35 |
Correct |
85 ms |
52232 KB |
Output is correct |
36 |
Correct |
104 ms |
52256 KB |
Output is correct |
37 |
Correct |
89 ms |
52136 KB |
Output is correct |
38 |
Correct |
75 ms |
52308 KB |
Output is correct |
39 |
Correct |
75 ms |
52224 KB |
Output is correct |
40 |
Correct |
77 ms |
52292 KB |
Output is correct |
41 |
Correct |
73 ms |
52240 KB |
Output is correct |
42 |
Correct |
74 ms |
52168 KB |
Output is correct |
43 |
Correct |
73 ms |
52168 KB |
Output is correct |
44 |
Correct |
71 ms |
52204 KB |
Output is correct |
45 |
Correct |
71 ms |
52284 KB |
Output is correct |
46 |
Correct |
71 ms |
52224 KB |
Output is correct |
47 |
Correct |
587 ms |
86740 KB |
Output is correct |
48 |
Correct |
2329 ms |
154820 KB |
Output is correct |
49 |
Correct |
2582 ms |
163404 KB |
Output is correct |
50 |
Correct |
2536 ms |
163468 KB |
Output is correct |
51 |
Correct |
2710 ms |
163448 KB |
Output is correct |
52 |
Correct |
2541 ms |
163440 KB |
Output is correct |
53 |
Correct |
2596 ms |
163404 KB |
Output is correct |
54 |
Correct |
2324 ms |
163400 KB |
Output is correct |
55 |
Correct |
2453 ms |
163456 KB |
Output is correct |
56 |
Correct |
2209 ms |
163476 KB |
Output is correct |
57 |
Correct |
2396 ms |
163544 KB |
Output is correct |
58 |
Correct |
2275 ms |
163428 KB |
Output is correct |
59 |
Correct |
2043 ms |
157556 KB |
Output is correct |
60 |
Correct |
1972 ms |
157600 KB |
Output is correct |
61 |
Correct |
1997 ms |
157612 KB |
Output is correct |
62 |
Correct |
1801 ms |
154712 KB |
Output is correct |
63 |
Correct |
1846 ms |
154628 KB |
Output is correct |
64 |
Correct |
1798 ms |
154716 KB |
Output is correct |
65 |
Correct |
1611 ms |
151816 KB |
Output is correct |
66 |
Correct |
1613 ms |
151784 KB |
Output is correct |
67 |
Correct |
1809 ms |
151864 KB |
Output is correct |