#define _CRT_SECURE_NO_WARNINGS
#include "bubblesort2.h"
#include <bits/stdc++.h>
#include <array>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/***************************JOI Open 18 - bubblesort***********************************/
const int inf = 1 << 20;
struct LazySegTree {
int sz;
v<int> data, lazy;
void init(int n, int val) {
data = v<int>(4 * n, val), lazy = v<int>(4 * n, 0);
sz = n;
}
void prop(int ind, int L, int R) {
if (lazy[ind] != 0) {
data[ind] += lazy[ind];
if (L != R) {
lazy[2 * ind] += lazy[ind];
lazy[2 * ind + 1] += lazy[ind];
}
lazy[ind] = 0;
}
}
void combine(int ind) {
data[ind] = max(data[2 * ind], data[2 * ind + 1]);
}
int query() {
return query(0, sz - 1, 1, 0, sz - 1);
}
void update(int lo, int hi, int val) {
update(lo, hi, val, 1, 0, sz - 1);
}
void update(int lo, int hi, int val, int ind, int L, int R) {
prop(ind, L, R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] += val;
prop(ind, L, R);
return;
}
int M = (L + R) / 2;
update(lo, hi, val, 2 * ind, L, M); update(lo, hi, val, 2 * ind + 1, M + 1, R);
combine(ind);
}
int query(int lo, int hi, int ind, int L, int R) {
prop(ind, L, R);
if (lo > R || L > hi) return -inf;
if (lo <= L && R <= hi) return data[ind];
int M = (L + R) / 2;
return max(query(lo, hi, 2 * ind, L, M), query(lo, hi, 2 * ind + 1, M + 1, R));
}
};
v<int> countScans(v<int> A, v<int> X, v<int> V) {
int n = A.size(), q = X.size();
// compress
v<pii> dat;
dat.reserve(n + q);
FOR(i, 0, n) dat.push_back({ A[i], i });
FOR(i, 0, q) dat.push_back({ V[i], X[i] });
sort(all(dat));
dat.resize(unique(all(dat)) - dat.begin());
FOR(i, 0, n) A[i] = lower_bound(all(dat), mp(A[i], i)) - dat.begin();
FOR(i, 0, q) V[i] = lower_bound(all(dat), mp(V[i], X[i])) - dat.begin();
// init
LazySegTree tree;
tree.init(dat.size(), -inf);
FOR(i, 0, n) {
tree.update(A[i] + 1, tree.sz - 1, -1);
tree.update(A[i], A[i], inf+i);
}
// process q
v<int> ans(q);
FOR(i, 0, q) {
int pos = X[i];
int _new = V[i];
int _old = A[pos];
tree.update(_old, _old, -inf - pos);
tree.update(_new, _new, inf + pos);
if (_new < _old)
tree.update(_new + 1, _old, -1);
else if (_new > _old)
tree.update(_old + 1, _new, +1);
A[pos] = _new;
ans[i] = tree.query();
}
return ans;
}
//
//int main() {
// io();
// countScans({ 1,2,3,4 }, { 0,2 }, { 3,1 });
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
8 ms |
512 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
8 ms |
512 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
18 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1132 KB |
Output is correct |
21 |
Correct |
27 ms |
1272 KB |
Output is correct |
22 |
Correct |
25 ms |
1152 KB |
Output is correct |
23 |
Correct |
20 ms |
1152 KB |
Output is correct |
24 |
Correct |
20 ms |
1152 KB |
Output is correct |
25 |
Correct |
20 ms |
896 KB |
Output is correct |
26 |
Correct |
19 ms |
1152 KB |
Output is correct |
27 |
Correct |
17 ms |
1024 KB |
Output is correct |
28 |
Correct |
18 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1792 KB |
Output is correct |
2 |
Correct |
109 ms |
3704 KB |
Output is correct |
3 |
Correct |
145 ms |
5644 KB |
Output is correct |
4 |
Correct |
169 ms |
5624 KB |
Output is correct |
5 |
Correct |
151 ms |
5752 KB |
Output is correct |
6 |
Correct |
202 ms |
5624 KB |
Output is correct |
7 |
Correct |
147 ms |
5368 KB |
Output is correct |
8 |
Correct |
156 ms |
5576 KB |
Output is correct |
9 |
Correct |
142 ms |
5472 KB |
Output is correct |
10 |
Correct |
139 ms |
4288 KB |
Output is correct |
11 |
Correct |
109 ms |
4292 KB |
Output is correct |
12 |
Correct |
108 ms |
4216 KB |
Output is correct |
13 |
Correct |
96 ms |
4216 KB |
Output is correct |
14 |
Correct |
94 ms |
4172 KB |
Output is correct |
15 |
Correct |
94 ms |
4188 KB |
Output is correct |
16 |
Correct |
115 ms |
4244 KB |
Output is correct |
17 |
Correct |
98 ms |
4216 KB |
Output is correct |
18 |
Correct |
94 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
8 ms |
512 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
18 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1132 KB |
Output is correct |
21 |
Correct |
27 ms |
1272 KB |
Output is correct |
22 |
Correct |
25 ms |
1152 KB |
Output is correct |
23 |
Correct |
20 ms |
1152 KB |
Output is correct |
24 |
Correct |
20 ms |
1152 KB |
Output is correct |
25 |
Correct |
20 ms |
896 KB |
Output is correct |
26 |
Correct |
19 ms |
1152 KB |
Output is correct |
27 |
Correct |
17 ms |
1024 KB |
Output is correct |
28 |
Correct |
18 ms |
1024 KB |
Output is correct |
29 |
Correct |
32 ms |
1792 KB |
Output is correct |
30 |
Correct |
109 ms |
3704 KB |
Output is correct |
31 |
Correct |
145 ms |
5644 KB |
Output is correct |
32 |
Correct |
169 ms |
5624 KB |
Output is correct |
33 |
Correct |
151 ms |
5752 KB |
Output is correct |
34 |
Correct |
202 ms |
5624 KB |
Output is correct |
35 |
Correct |
147 ms |
5368 KB |
Output is correct |
36 |
Correct |
156 ms |
5576 KB |
Output is correct |
37 |
Correct |
142 ms |
5472 KB |
Output is correct |
38 |
Correct |
139 ms |
4288 KB |
Output is correct |
39 |
Correct |
109 ms |
4292 KB |
Output is correct |
40 |
Correct |
108 ms |
4216 KB |
Output is correct |
41 |
Correct |
96 ms |
4216 KB |
Output is correct |
42 |
Correct |
94 ms |
4172 KB |
Output is correct |
43 |
Correct |
94 ms |
4188 KB |
Output is correct |
44 |
Correct |
115 ms |
4244 KB |
Output is correct |
45 |
Correct |
98 ms |
4216 KB |
Output is correct |
46 |
Correct |
94 ms |
4216 KB |
Output is correct |
47 |
Correct |
607 ms |
15872 KB |
Output is correct |
48 |
Correct |
2326 ms |
53112 KB |
Output is correct |
49 |
Correct |
2581 ms |
57436 KB |
Output is correct |
50 |
Correct |
2492 ms |
57336 KB |
Output is correct |
51 |
Correct |
2694 ms |
57436 KB |
Output is correct |
52 |
Correct |
2641 ms |
57364 KB |
Output is correct |
53 |
Correct |
2901 ms |
57464 KB |
Output is correct |
54 |
Correct |
2455 ms |
57368 KB |
Output is correct |
55 |
Correct |
2569 ms |
57336 KB |
Output is correct |
56 |
Correct |
2609 ms |
57336 KB |
Output is correct |
57 |
Correct |
2574 ms |
57244 KB |
Output is correct |
58 |
Correct |
2473 ms |
57336 KB |
Output is correct |
59 |
Correct |
2095 ms |
53468 KB |
Output is correct |
60 |
Correct |
2477 ms |
53368 KB |
Output is correct |
61 |
Correct |
2170 ms |
53288 KB |
Output is correct |
62 |
Correct |
1980 ms |
51448 KB |
Output is correct |
63 |
Correct |
1992 ms |
51428 KB |
Output is correct |
64 |
Correct |
2144 ms |
51448 KB |
Output is correct |
65 |
Correct |
2085 ms |
49180 KB |
Output is correct |
66 |
Correct |
2164 ms |
49400 KB |
Output is correct |
67 |
Correct |
2021 ms |
49276 KB |
Output is correct |