#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20;
const ll MAXN = 1e6 + 100;
vector<pair<int,int>> cc;
int index(pair<int,int> k) {
return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}
int sg[4*MAXN], lazy[4*MAXN];
void push(int k, int a, int b) {
if (lazy[k]) {
sg[k] += lazy[k];
if (a != b) {
lazy[2*k] += lazy[k];
lazy[2*k+1] += lazy[k];
}
lazy[k] = 0;
return ;
}
}
void update(int k, int a, int b, int q_l, int q_r, int val) {
push(k, a, b);
if (b < q_l || a > q_r)
return ;
if (q_l <= a && b <= q_r) {
lazy[k] += val;
push(k, a, b);
return ;
}
update(2*k, a, (a+b)/2, q_l, q_r, val);
update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
sg[k] = max(sg[2*k], sg[2*k+1]);
}
int query(int k, int a, int b, int q_l, int q_r) {
push(k, a, b);
if (b < q_l || a > q_r)
return 0;
if (q_l <= a && b <= q_r)
return sg[k];
return max(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}
int N;
void add(pair<int,int> p) {
int plc = index(p);
update(1, 1, N, plc, plc, 1e7 + p.s);
update(1, 1, N, plc + 1, N, -1);
}
void omit(pair<int,int> p) {
int plc = index(p);
update(1, 1, N, plc, plc, -1e7 - p.s);
update(1, 1, N, plc + 1, N, 1);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
memset(lazy, 0, sizeof(lazy));
memset(sg, 0, sizeof(sg));
int n = A.size(), q = V.size();
for (int i = 0; i < n; i++)
cc.push_back({A[i], i});
for (int i = 0; i < q; i++)
cc.push_back({V[i], X[i]});
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
N = cc.size();
update(1, 1, N, 1, N, -1e7);
push(1, 1, N);
for (int i = 0; i < n; i++)
add({A[i], i});
push(1, 1, N);
vector<int> res;
for (int i = 0; i < q; i++) {
omit({A[X[i]], X[i]});
add({V[i], X[i]});
A[X[i]] = V[i];
push(1, 1, N);
res.push_back(sg[1]);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31576 KB |
Output is correct |
2 |
Correct |
5 ms |
31580 KB |
Output is correct |
3 |
Correct |
7 ms |
31724 KB |
Output is correct |
4 |
Correct |
8 ms |
31900 KB |
Output is correct |
5 |
Correct |
7 ms |
31836 KB |
Output is correct |
6 |
Correct |
7 ms |
31728 KB |
Output is correct |
7 |
Correct |
8 ms |
31836 KB |
Output is correct |
8 |
Correct |
8 ms |
31832 KB |
Output is correct |
9 |
Correct |
8 ms |
32088 KB |
Output is correct |
10 |
Correct |
7 ms |
31704 KB |
Output is correct |
11 |
Correct |
8 ms |
31836 KB |
Output is correct |
12 |
Correct |
7 ms |
31684 KB |
Output is correct |
13 |
Correct |
7 ms |
31712 KB |
Output is correct |
14 |
Correct |
8 ms |
31832 KB |
Output is correct |
15 |
Correct |
7 ms |
31836 KB |
Output is correct |
16 |
Correct |
8 ms |
31728 KB |
Output is correct |
17 |
Correct |
8 ms |
31832 KB |
Output is correct |
18 |
Correct |
7 ms |
32088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31576 KB |
Output is correct |
2 |
Correct |
5 ms |
31580 KB |
Output is correct |
3 |
Correct |
7 ms |
31724 KB |
Output is correct |
4 |
Correct |
8 ms |
31900 KB |
Output is correct |
5 |
Correct |
7 ms |
31836 KB |
Output is correct |
6 |
Correct |
7 ms |
31728 KB |
Output is correct |
7 |
Correct |
8 ms |
31836 KB |
Output is correct |
8 |
Correct |
8 ms |
31832 KB |
Output is correct |
9 |
Correct |
8 ms |
32088 KB |
Output is correct |
10 |
Correct |
7 ms |
31704 KB |
Output is correct |
11 |
Correct |
8 ms |
31836 KB |
Output is correct |
12 |
Correct |
7 ms |
31684 KB |
Output is correct |
13 |
Correct |
7 ms |
31712 KB |
Output is correct |
14 |
Correct |
8 ms |
31832 KB |
Output is correct |
15 |
Correct |
7 ms |
31836 KB |
Output is correct |
16 |
Correct |
8 ms |
31728 KB |
Output is correct |
17 |
Correct |
8 ms |
31832 KB |
Output is correct |
18 |
Correct |
7 ms |
32088 KB |
Output is correct |
19 |
Correct |
17 ms |
32348 KB |
Output is correct |
20 |
Correct |
20 ms |
32384 KB |
Output is correct |
21 |
Correct |
19 ms |
32348 KB |
Output is correct |
22 |
Correct |
20 ms |
32396 KB |
Output is correct |
23 |
Correct |
18 ms |
32348 KB |
Output is correct |
24 |
Correct |
18 ms |
32348 KB |
Output is correct |
25 |
Correct |
20 ms |
32356 KB |
Output is correct |
26 |
Correct |
18 ms |
32348 KB |
Output is correct |
27 |
Correct |
19 ms |
32352 KB |
Output is correct |
28 |
Correct |
18 ms |
32348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
32348 KB |
Output is correct |
2 |
Correct |
72 ms |
33380 KB |
Output is correct |
3 |
Correct |
114 ms |
34516 KB |
Output is correct |
4 |
Correct |
115 ms |
34504 KB |
Output is correct |
5 |
Correct |
114 ms |
34516 KB |
Output is correct |
6 |
Correct |
123 ms |
34688 KB |
Output is correct |
7 |
Correct |
118 ms |
34668 KB |
Output is correct |
8 |
Correct |
114 ms |
34668 KB |
Output is correct |
9 |
Correct |
115 ms |
34684 KB |
Output is correct |
10 |
Correct |
100 ms |
34752 KB |
Output is correct |
11 |
Correct |
94 ms |
34752 KB |
Output is correct |
12 |
Correct |
93 ms |
34744 KB |
Output is correct |
13 |
Correct |
92 ms |
34760 KB |
Output is correct |
14 |
Correct |
92 ms |
34752 KB |
Output is correct |
15 |
Correct |
91 ms |
34744 KB |
Output is correct |
16 |
Correct |
89 ms |
34732 KB |
Output is correct |
17 |
Correct |
89 ms |
34756 KB |
Output is correct |
18 |
Correct |
90 ms |
34756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31576 KB |
Output is correct |
2 |
Correct |
5 ms |
31580 KB |
Output is correct |
3 |
Correct |
7 ms |
31724 KB |
Output is correct |
4 |
Correct |
8 ms |
31900 KB |
Output is correct |
5 |
Correct |
7 ms |
31836 KB |
Output is correct |
6 |
Correct |
7 ms |
31728 KB |
Output is correct |
7 |
Correct |
8 ms |
31836 KB |
Output is correct |
8 |
Correct |
8 ms |
31832 KB |
Output is correct |
9 |
Correct |
8 ms |
32088 KB |
Output is correct |
10 |
Correct |
7 ms |
31704 KB |
Output is correct |
11 |
Correct |
8 ms |
31836 KB |
Output is correct |
12 |
Correct |
7 ms |
31684 KB |
Output is correct |
13 |
Correct |
7 ms |
31712 KB |
Output is correct |
14 |
Correct |
8 ms |
31832 KB |
Output is correct |
15 |
Correct |
7 ms |
31836 KB |
Output is correct |
16 |
Correct |
8 ms |
31728 KB |
Output is correct |
17 |
Correct |
8 ms |
31832 KB |
Output is correct |
18 |
Correct |
7 ms |
32088 KB |
Output is correct |
19 |
Correct |
17 ms |
32348 KB |
Output is correct |
20 |
Correct |
20 ms |
32384 KB |
Output is correct |
21 |
Correct |
19 ms |
32348 KB |
Output is correct |
22 |
Correct |
20 ms |
32396 KB |
Output is correct |
23 |
Correct |
18 ms |
32348 KB |
Output is correct |
24 |
Correct |
18 ms |
32348 KB |
Output is correct |
25 |
Correct |
20 ms |
32356 KB |
Output is correct |
26 |
Correct |
18 ms |
32348 KB |
Output is correct |
27 |
Correct |
19 ms |
32352 KB |
Output is correct |
28 |
Correct |
18 ms |
32348 KB |
Output is correct |
29 |
Correct |
25 ms |
32348 KB |
Output is correct |
30 |
Correct |
72 ms |
33380 KB |
Output is correct |
31 |
Correct |
114 ms |
34516 KB |
Output is correct |
32 |
Correct |
115 ms |
34504 KB |
Output is correct |
33 |
Correct |
114 ms |
34516 KB |
Output is correct |
34 |
Correct |
123 ms |
34688 KB |
Output is correct |
35 |
Correct |
118 ms |
34668 KB |
Output is correct |
36 |
Correct |
114 ms |
34668 KB |
Output is correct |
37 |
Correct |
115 ms |
34684 KB |
Output is correct |
38 |
Correct |
100 ms |
34752 KB |
Output is correct |
39 |
Correct |
94 ms |
34752 KB |
Output is correct |
40 |
Correct |
93 ms |
34744 KB |
Output is correct |
41 |
Correct |
92 ms |
34760 KB |
Output is correct |
42 |
Correct |
92 ms |
34752 KB |
Output is correct |
43 |
Correct |
91 ms |
34744 KB |
Output is correct |
44 |
Correct |
89 ms |
34732 KB |
Output is correct |
45 |
Correct |
89 ms |
34756 KB |
Output is correct |
46 |
Correct |
90 ms |
34756 KB |
Output is correct |
47 |
Correct |
377 ms |
43200 KB |
Output is correct |
48 |
Correct |
1614 ms |
66200 KB |
Output is correct |
49 |
Correct |
1766 ms |
68212 KB |
Output is correct |
50 |
Correct |
1741 ms |
68656 KB |
Output is correct |
51 |
Correct |
1701 ms |
67988 KB |
Output is correct |
52 |
Correct |
1739 ms |
68400 KB |
Output is correct |
53 |
Correct |
1747 ms |
67996 KB |
Output is correct |
54 |
Correct |
1601 ms |
68228 KB |
Output is correct |
55 |
Correct |
1646 ms |
68384 KB |
Output is correct |
56 |
Correct |
1600 ms |
68596 KB |
Output is correct |
57 |
Correct |
1663 ms |
68620 KB |
Output is correct |
58 |
Correct |
1590 ms |
68592 KB |
Output is correct |
59 |
Correct |
1428 ms |
67048 KB |
Output is correct |
60 |
Correct |
1444 ms |
67152 KB |
Output is correct |
61 |
Correct |
1439 ms |
66976 KB |
Output is correct |
62 |
Correct |
1403 ms |
66828 KB |
Output is correct |
63 |
Correct |
1395 ms |
66708 KB |
Output is correct |
64 |
Correct |
1409 ms |
66812 KB |
Output is correct |
65 |
Correct |
1264 ms |
66700 KB |
Output is correct |
66 |
Correct |
1309 ms |
66676 KB |
Output is correct |
67 |
Correct |
1406 ms |
66624 KB |
Output is correct |