#include "bubblesort2.h"
#include <bits/stdc++.h>
#define mid ((st+dr)>>1)
#define left_son (node<<1)
#define right_son ((node<<1)|1)
using namespace std;
const int Nmax = 1e6 + 5, lim = 1e6, inf = 1e6;
typedef long long ll;
ll a[Nmax], val[Nmax];
class SegmentTree
{
int lazy[Nmax<<2], a[Nmax<<2];
public:
void add(int node, int st, int dr, int L, int R, int Add)
{
if(L <= st && dr <= R)
{
lazy[node] += Add;
return;
}
if(L <= mid) add(left_son, st, mid, L, R, Add);
if(mid < R) add(right_son, mid+1, dr, L, R, Add);
a[node] = max(a[left_son] + lazy[left_son], a[right_son] + lazy[right_son]);
}
int query()
{
return a[1] + lazy[1];
}
void init(int node, int st, int dr)
{
a[node] = -inf; lazy[node] = 0;
if(st == dr) return;
init(left_son, st, mid); init(right_son, mid+1, dr);
}
} aint;
int Search(vector<ll> &a, ll val)
{
int st = 0, dr = a.size() - 1;
while(st <= dr)
if(a[mid] < val) st = mid+1;
else dr = mid-1;
return st + 1;
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
int N = A.size(), i;
int Q = V.size();
for(i=0; i<N; ++i) a[i] = (ll) lim * A[i] + i;
for(i=0; i<Q; ++i) val[i] = (ll) lim * V[i] + X[i];
vector<ll> vals;
for(i=0; i<N; ++i) vals.push_back(a[i]);
for(i=0; i<Q; ++i) vals.push_back(val[i]);
sort(vals.begin(), vals.end());
int cnt = vals.size();
aint.init(1, 1, cnt);
for(i=0; i<N; ++i)
{
int pos = Search(vals, (a[i]));
aint.add(1, 1, cnt, pos, pos, +inf+i);
aint.add(1, 1, cnt, 1, pos, +1);
}
vector<int> answer(Q);
for(i=0; i<Q; ++i)
{
int pos = Search(vals, a[X[i]]);
aint.add(1, 1, cnt, 1, pos, -1);
aint.add(1, 1, cnt, pos, pos, -inf-X[i]);
a[X[i]] = val[i];
int act = Search(vals, val[i]);
aint.add(1, 1, cnt, act, act, +inf+X[i]);
aint.add(1, 1, cnt, 1, act, 1);
answer[i] = aint.query() - N;
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
7 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
8 ms |
640 KB |
Output is correct |
10 |
Correct |
5 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 |
5 ms |
636 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
8 ms |
640 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
8 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
7 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
8 ms |
640 KB |
Output is correct |
10 |
Correct |
5 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 |
5 ms |
636 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
8 ms |
640 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
8 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
16 ms |
1296 KB |
Output is correct |
20 |
Correct |
18 ms |
1448 KB |
Output is correct |
21 |
Correct |
17 ms |
1408 KB |
Output is correct |
22 |
Correct |
20 ms |
1408 KB |
Output is correct |
23 |
Correct |
23 ms |
1312 KB |
Output is correct |
24 |
Correct |
17 ms |
1280 KB |
Output is correct |
25 |
Correct |
18 ms |
1280 KB |
Output is correct |
26 |
Correct |
17 ms |
1408 KB |
Output is correct |
27 |
Correct |
18 ms |
1280 KB |
Output is correct |
28 |
Correct |
19 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1916 KB |
Output is correct |
2 |
Correct |
84 ms |
3568 KB |
Output is correct |
3 |
Correct |
159 ms |
5612 KB |
Output is correct |
4 |
Correct |
172 ms |
5660 KB |
Output is correct |
5 |
Correct |
150 ms |
5484 KB |
Output is correct |
6 |
Correct |
145 ms |
5612 KB |
Output is correct |
7 |
Correct |
151 ms |
5612 KB |
Output is correct |
8 |
Correct |
179 ms |
5580 KB |
Output is correct |
9 |
Correct |
145 ms |
5612 KB |
Output is correct |
10 |
Correct |
167 ms |
5612 KB |
Output is correct |
11 |
Correct |
145 ms |
5528 KB |
Output is correct |
12 |
Correct |
115 ms |
5612 KB |
Output is correct |
13 |
Correct |
113 ms |
5580 KB |
Output is correct |
14 |
Correct |
121 ms |
5612 KB |
Output is correct |
15 |
Correct |
122 ms |
5612 KB |
Output is correct |
16 |
Correct |
110 ms |
5564 KB |
Output is correct |
17 |
Correct |
100 ms |
5612 KB |
Output is correct |
18 |
Correct |
134 ms |
5612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
7 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
8 ms |
640 KB |
Output is correct |
10 |
Correct |
5 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 |
5 ms |
636 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
8 ms |
640 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
8 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
16 ms |
1296 KB |
Output is correct |
20 |
Correct |
18 ms |
1448 KB |
Output is correct |
21 |
Correct |
17 ms |
1408 KB |
Output is correct |
22 |
Correct |
20 ms |
1408 KB |
Output is correct |
23 |
Correct |
23 ms |
1312 KB |
Output is correct |
24 |
Correct |
17 ms |
1280 KB |
Output is correct |
25 |
Correct |
18 ms |
1280 KB |
Output is correct |
26 |
Correct |
17 ms |
1408 KB |
Output is correct |
27 |
Correct |
18 ms |
1280 KB |
Output is correct |
28 |
Correct |
19 ms |
1280 KB |
Output is correct |
29 |
Correct |
31 ms |
1916 KB |
Output is correct |
30 |
Correct |
84 ms |
3568 KB |
Output is correct |
31 |
Correct |
159 ms |
5612 KB |
Output is correct |
32 |
Correct |
172 ms |
5660 KB |
Output is correct |
33 |
Correct |
150 ms |
5484 KB |
Output is correct |
34 |
Correct |
145 ms |
5612 KB |
Output is correct |
35 |
Correct |
151 ms |
5612 KB |
Output is correct |
36 |
Correct |
179 ms |
5580 KB |
Output is correct |
37 |
Correct |
145 ms |
5612 KB |
Output is correct |
38 |
Correct |
167 ms |
5612 KB |
Output is correct |
39 |
Correct |
145 ms |
5528 KB |
Output is correct |
40 |
Correct |
115 ms |
5612 KB |
Output is correct |
41 |
Correct |
113 ms |
5580 KB |
Output is correct |
42 |
Correct |
121 ms |
5612 KB |
Output is correct |
43 |
Correct |
122 ms |
5612 KB |
Output is correct |
44 |
Correct |
110 ms |
5564 KB |
Output is correct |
45 |
Correct |
100 ms |
5612 KB |
Output is correct |
46 |
Correct |
134 ms |
5612 KB |
Output is correct |
47 |
Correct |
592 ms |
17480 KB |
Output is correct |
48 |
Correct |
2567 ms |
44132 KB |
Output is correct |
49 |
Correct |
2680 ms |
46600 KB |
Output is correct |
50 |
Correct |
2698 ms |
46328 KB |
Output is correct |
51 |
Correct |
2684 ms |
46528 KB |
Output is correct |
52 |
Correct |
2777 ms |
46548 KB |
Output is correct |
53 |
Correct |
2978 ms |
46420 KB |
Output is correct |
54 |
Correct |
2646 ms |
46472 KB |
Output is correct |
55 |
Correct |
3010 ms |
46580 KB |
Output is correct |
56 |
Correct |
2559 ms |
46616 KB |
Output is correct |
57 |
Correct |
2433 ms |
46540 KB |
Output is correct |
58 |
Correct |
2510 ms |
46628 KB |
Output is correct |
59 |
Correct |
2228 ms |
46488 KB |
Output is correct |
60 |
Correct |
2359 ms |
46472 KB |
Output is correct |
61 |
Correct |
2351 ms |
46480 KB |
Output is correct |
62 |
Correct |
2159 ms |
46468 KB |
Output is correct |
63 |
Correct |
2286 ms |
46484 KB |
Output is correct |
64 |
Correct |
2053 ms |
46536 KB |
Output is correct |
65 |
Correct |
2021 ms |
46524 KB |
Output is correct |
66 |
Correct |
2045 ms |
46460 KB |
Output is correct |
67 |
Correct |
1966 ms |
46428 KB |
Output is correct |