#include "bubblesort2.h"
#include<vector>
#include<algorithm>
#define DIM 1000005
#define f first
#define s second
using namespace std;
static vector<int> sol;
struct str{
int p, val, ind, inds;
};
static str v[DIM];
static int lst[DIM];
static pair<int, int> aint[4 * DIM];
static int cmp1(str a, str b){
if(a.val == b.val){
return a.p < b.p;
}
return a.val < b.val;
}
static int cmp2(str a, str b){
return a.ind < b.ind;
}
static void update(int nod, int st, int dr, int p, int u, int val){
if(p <= st && dr <= u){
aint[nod].s += val;
}
else{
int mid = (st + dr) / 2;
aint[2 * nod].s += aint[nod].s;
aint[2 * nod + 1].s += aint[nod].s;
aint[nod].s = 0;
if(p <= mid){
update(2 * nod, st, mid, p, u, val);
}
if(u > mid){
update(2 * nod + 1, mid + 1, dr, p, u, val);
}
aint[nod].f = max(aint[2 * nod].f + aint[2 * nod].s, aint[2 * nod + 1].f + aint[2 * nod + 1].s);
}
}
vector<int> countScans(vector<int> a, vector<int> xq, vector<int> yq){
int n, q, i;
n = a.size();
q = xq.size();
sol.resize(q);
for(i = 1; i <= n; i++){
v[i] = {i, a[i - 1], i, 0};
}
for(i = 1; i <= q; i++){
v[i + n] = {xq[i - 1] + 1, yq[i - 1], i + n, 0};
}
sort(v + 1, v + n + q + 1, cmp1);
for(i = 1; i <= n + q; i++){
v[i].inds = i;
if(v[i].ind <= n){
update(1, 1, n + q, i, n + q, -1);
update(1, 1, n + q, i, i, v[i].p);
}
}
sort(v + 1, v + n + q + 1, cmp2);
for(i = 1; i <= n; i++){
lst[ v[i].p ] = v[i].inds;
}
for(i = n + 1; i <= n + q; i++){
update(1, 1, n + q, lst[ v[i].p ], n + q, 1);
update(1, 1, n + q, lst[ v[i].p ], lst[ v[i].p ], -v[i].p);
update(1, 1, n + q, v[i].inds, n + q, -1);
update(1, 1, n + q, v[i].inds, v[i].inds, v[i].p);
lst[ v[i].p ] = v[i].inds;
sol[i - n - 1] = aint[1].f + aint[1].s;
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
544 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
544 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
19 |
Correct |
16 ms |
1280 KB |
Output is correct |
20 |
Correct |
22 ms |
1408 KB |
Output is correct |
21 |
Correct |
18 ms |
1408 KB |
Output is correct |
22 |
Correct |
20 ms |
1408 KB |
Output is correct |
23 |
Correct |
18 ms |
1280 KB |
Output is correct |
24 |
Correct |
20 ms |
1280 KB |
Output is correct |
25 |
Correct |
17 ms |
1280 KB |
Output is correct |
26 |
Correct |
22 ms |
1280 KB |
Output is correct |
27 |
Correct |
17 ms |
1280 KB |
Output is correct |
28 |
Correct |
18 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1912 KB |
Output is correct |
2 |
Correct |
75 ms |
3704 KB |
Output is correct |
3 |
Correct |
145 ms |
6364 KB |
Output is correct |
4 |
Correct |
139 ms |
6264 KB |
Output is correct |
5 |
Correct |
136 ms |
6264 KB |
Output is correct |
6 |
Correct |
144 ms |
6264 KB |
Output is correct |
7 |
Correct |
140 ms |
6320 KB |
Output is correct |
8 |
Correct |
135 ms |
6276 KB |
Output is correct |
9 |
Correct |
130 ms |
6340 KB |
Output is correct |
10 |
Correct |
125 ms |
6392 KB |
Output is correct |
11 |
Correct |
127 ms |
6392 KB |
Output is correct |
12 |
Correct |
124 ms |
6396 KB |
Output is correct |
13 |
Correct |
134 ms |
6412 KB |
Output is correct |
14 |
Correct |
132 ms |
6356 KB |
Output is correct |
15 |
Correct |
140 ms |
6328 KB |
Output is correct |
16 |
Correct |
116 ms |
6384 KB |
Output is correct |
17 |
Correct |
117 ms |
6392 KB |
Output is correct |
18 |
Correct |
141 ms |
6392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
544 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
19 |
Correct |
16 ms |
1280 KB |
Output is correct |
20 |
Correct |
22 ms |
1408 KB |
Output is correct |
21 |
Correct |
18 ms |
1408 KB |
Output is correct |
22 |
Correct |
20 ms |
1408 KB |
Output is correct |
23 |
Correct |
18 ms |
1280 KB |
Output is correct |
24 |
Correct |
20 ms |
1280 KB |
Output is correct |
25 |
Correct |
17 ms |
1280 KB |
Output is correct |
26 |
Correct |
22 ms |
1280 KB |
Output is correct |
27 |
Correct |
17 ms |
1280 KB |
Output is correct |
28 |
Correct |
18 ms |
1280 KB |
Output is correct |
29 |
Correct |
23 ms |
1912 KB |
Output is correct |
30 |
Correct |
75 ms |
3704 KB |
Output is correct |
31 |
Correct |
145 ms |
6364 KB |
Output is correct |
32 |
Correct |
139 ms |
6264 KB |
Output is correct |
33 |
Correct |
136 ms |
6264 KB |
Output is correct |
34 |
Correct |
144 ms |
6264 KB |
Output is correct |
35 |
Correct |
140 ms |
6320 KB |
Output is correct |
36 |
Correct |
135 ms |
6276 KB |
Output is correct |
37 |
Correct |
130 ms |
6340 KB |
Output is correct |
38 |
Correct |
125 ms |
6392 KB |
Output is correct |
39 |
Correct |
127 ms |
6392 KB |
Output is correct |
40 |
Correct |
124 ms |
6396 KB |
Output is correct |
41 |
Correct |
134 ms |
6412 KB |
Output is correct |
42 |
Correct |
132 ms |
6356 KB |
Output is correct |
43 |
Correct |
140 ms |
6328 KB |
Output is correct |
44 |
Correct |
116 ms |
6384 KB |
Output is correct |
45 |
Correct |
117 ms |
6392 KB |
Output is correct |
46 |
Correct |
141 ms |
6392 KB |
Output is correct |
47 |
Correct |
457 ms |
22136 KB |
Output is correct |
48 |
Correct |
1719 ms |
59336 KB |
Output is correct |
49 |
Correct |
1797 ms |
63096 KB |
Output is correct |
50 |
Correct |
1805 ms |
63096 KB |
Output is correct |
51 |
Correct |
1772 ms |
62996 KB |
Output is correct |
52 |
Correct |
1794 ms |
63036 KB |
Output is correct |
53 |
Correct |
1770 ms |
63056 KB |
Output is correct |
54 |
Correct |
1771 ms |
63352 KB |
Output is correct |
55 |
Correct |
1757 ms |
63300 KB |
Output is correct |
56 |
Correct |
1749 ms |
63096 KB |
Output is correct |
57 |
Correct |
1807 ms |
63224 KB |
Output is correct |
58 |
Correct |
1756 ms |
63096 KB |
Output is correct |
59 |
Correct |
1669 ms |
61688 KB |
Output is correct |
60 |
Correct |
1650 ms |
61892 KB |
Output is correct |
61 |
Correct |
1661 ms |
61688 KB |
Output is correct |
62 |
Correct |
1647 ms |
61708 KB |
Output is correct |
63 |
Correct |
1649 ms |
61636 KB |
Output is correct |
64 |
Correct |
1665 ms |
61688 KB |
Output is correct |
65 |
Correct |
1593 ms |
61560 KB |
Output is correct |
66 |
Correct |
1595 ms |
61560 KB |
Output is correct |
67 |
Correct |
1595 ms |
61584 KB |
Output is correct |