Submission #633936

# Submission time Handle Problem Language Result Execution time Memory
633936 2022-08-23T13:16:40 Z Arinoor Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3216 ms 66832 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x)			x.begin(), x.end()
#define pb				push_back
#define mp				make_pair
#define fi				first
#define se				second
#define bug(x)			cerr << #x << " : " << x << '\n'
#define mid				((l + r) >> 1)
#define lc				(id << 1)
#define rc				(lc | 1)

typedef pair<int, int> pii;
const int maxn = 1e6 + 10;
const int inf = 1e9 + 10;

int n, q, m, a[maxn];
int seg[maxn << 2], lz[maxn << 2];
int fen[maxn];
vector<pii> C;

void shift(int id, int l, int r);

void add(int id, int l, int r, int ql, int qr, int x){
	if(qr <= l or r <= ql)
		return;
	if(l >= ql and r <= qr){
		seg[id] += x;
		lz[id] += x;
		return;
	}
	shift(id, l, r);
	add(lc, l, mid, ql, qr, x);
	add(rc, mid, r, ql, qr, x);
	seg[id] = max(seg[lc], seg[rc]);
}

void change(int id, int l, int r, int p, int x){
	if(l + 1 == r){
		seg[id] = x;
		return;
	}
	shift(id, l, r);
	if(p < mid)
		change(lc, l, mid, p, x);
	else
		change(rc, mid, r, p, x);
	seg[id] = max(seg[lc], seg[rc]);
}

void shift(int id, int l, int r){
	if(!lz[id])
		return;
	add(lc, l, mid, l, mid, lz[id]);
	add(rc, mid, r, mid, r, lz[id]);
	lz[id] = 0;
}

void add(int i, int x){
	for(i ++; i <= m; i += i & -i)
		fen[i] += x;
}

int get(int i){
	int res = 0;
	for(; i; i -= i & -i)
		res += fen[i];
	return res;
}

int get(int l, int r){
	return get(r) - get(l);
}

void add(int x, int i, int val){
	int ind = lower_bound(all(C), mp(x, i)) - C.begin();
	int r = lower_bound(all(C), mp(x, -inf)) - C.begin();
	int l = upper_bound(all(C), mp(x, inf)) - C.begin();
	add(ind, val);
	add(1, 0, m, 0, r, val);
	if(val == -1){
		change(1, 0, m, ind, -inf);
	}
	else{
		int res = get(l, m) - (n - 1 - i);
		change(1, 0, m, ind, res);
	}
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	n = A.size();
	q = X.size();
	for(int i = 0; i < n; i ++)
		C.pb(mp(A[i], i));
	for(int i = 0; i < q; i ++)
		C.pb(mp(V[i], X[i]));
	sort(all(C));
	C.resize(unique(all(C)) - C.begin());
	m = C.size();
	fill_n(seg, maxn << 2, -inf);
	for(int i = 0; i < n; i ++){
		a[i] = A[i];
		add(a[i], i, 1);
	}
	vector<int> ans;
	for(int i = 0; i < q; i ++){
		add(a[X[i]], X[i], -1);
		a[X[i]] = V[i];
		add(a[X[i]], X[i], 1);
		ans.pb(seg[1]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Correct 10 ms 15952 KB Output is correct
3 Correct 14 ms 16084 KB Output is correct
4 Correct 13 ms 16192 KB Output is correct
5 Correct 13 ms 16080 KB Output is correct
6 Correct 13 ms 16188 KB Output is correct
7 Correct 12 ms 16188 KB Output is correct
8 Correct 13 ms 16192 KB Output is correct
9 Correct 12 ms 16084 KB Output is correct
10 Correct 12 ms 16084 KB Output is correct
11 Correct 14 ms 16084 KB Output is correct
12 Correct 15 ms 16084 KB Output is correct
13 Correct 11 ms 16084 KB Output is correct
14 Correct 12 ms 16060 KB Output is correct
15 Correct 12 ms 16120 KB Output is correct
16 Correct 12 ms 16060 KB Output is correct
17 Correct 13 ms 16084 KB Output is correct
18 Correct 12 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Correct 10 ms 15952 KB Output is correct
3 Correct 14 ms 16084 KB Output is correct
4 Correct 13 ms 16192 KB Output is correct
5 Correct 13 ms 16080 KB Output is correct
6 Correct 13 ms 16188 KB Output is correct
7 Correct 12 ms 16188 KB Output is correct
8 Correct 13 ms 16192 KB Output is correct
9 Correct 12 ms 16084 KB Output is correct
10 Correct 12 ms 16084 KB Output is correct
11 Correct 14 ms 16084 KB Output is correct
12 Correct 15 ms 16084 KB Output is correct
13 Correct 11 ms 16084 KB Output is correct
14 Correct 12 ms 16060 KB Output is correct
15 Correct 12 ms 16120 KB Output is correct
16 Correct 12 ms 16060 KB Output is correct
17 Correct 13 ms 16084 KB Output is correct
18 Correct 12 ms 16084 KB Output is correct
19 Correct 32 ms 16724 KB Output is correct
20 Correct 31 ms 16828 KB Output is correct
21 Correct 31 ms 16844 KB Output is correct
22 Correct 41 ms 16832 KB Output is correct
23 Correct 31 ms 16792 KB Output is correct
24 Correct 35 ms 16796 KB Output is correct
25 Correct 28 ms 16716 KB Output is correct
26 Correct 29 ms 16812 KB Output is correct
27 Correct 25 ms 16792 KB Output is correct
28 Correct 26 ms 16828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 17060 KB Output is correct
2 Correct 115 ms 18536 KB Output is correct
3 Correct 182 ms 20484 KB Output is correct
4 Correct 187 ms 20640 KB Output is correct
5 Correct 172 ms 20500 KB Output is correct
6 Correct 178 ms 20492 KB Output is correct
7 Correct 174 ms 20552 KB Output is correct
8 Correct 186 ms 20480 KB Output is correct
9 Correct 205 ms 20528 KB Output is correct
10 Correct 113 ms 19436 KB Output is correct
11 Correct 112 ms 19516 KB Output is correct
12 Correct 112 ms 19520 KB Output is correct
13 Correct 113 ms 19536 KB Output is correct
14 Correct 113 ms 19496 KB Output is correct
15 Correct 119 ms 19568 KB Output is correct
16 Correct 110 ms 19444 KB Output is correct
17 Correct 107 ms 19516 KB Output is correct
18 Correct 108 ms 19540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Correct 10 ms 15952 KB Output is correct
3 Correct 14 ms 16084 KB Output is correct
4 Correct 13 ms 16192 KB Output is correct
5 Correct 13 ms 16080 KB Output is correct
6 Correct 13 ms 16188 KB Output is correct
7 Correct 12 ms 16188 KB Output is correct
8 Correct 13 ms 16192 KB Output is correct
9 Correct 12 ms 16084 KB Output is correct
10 Correct 12 ms 16084 KB Output is correct
11 Correct 14 ms 16084 KB Output is correct
12 Correct 15 ms 16084 KB Output is correct
13 Correct 11 ms 16084 KB Output is correct
14 Correct 12 ms 16060 KB Output is correct
15 Correct 12 ms 16120 KB Output is correct
16 Correct 12 ms 16060 KB Output is correct
17 Correct 13 ms 16084 KB Output is correct
18 Correct 12 ms 16084 KB Output is correct
19 Correct 32 ms 16724 KB Output is correct
20 Correct 31 ms 16828 KB Output is correct
21 Correct 31 ms 16844 KB Output is correct
22 Correct 41 ms 16832 KB Output is correct
23 Correct 31 ms 16792 KB Output is correct
24 Correct 35 ms 16796 KB Output is correct
25 Correct 28 ms 16716 KB Output is correct
26 Correct 29 ms 16812 KB Output is correct
27 Correct 25 ms 16792 KB Output is correct
28 Correct 26 ms 16828 KB Output is correct
29 Correct 39 ms 17060 KB Output is correct
30 Correct 115 ms 18536 KB Output is correct
31 Correct 182 ms 20484 KB Output is correct
32 Correct 187 ms 20640 KB Output is correct
33 Correct 172 ms 20500 KB Output is correct
34 Correct 178 ms 20492 KB Output is correct
35 Correct 174 ms 20552 KB Output is correct
36 Correct 186 ms 20480 KB Output is correct
37 Correct 205 ms 20528 KB Output is correct
38 Correct 113 ms 19436 KB Output is correct
39 Correct 112 ms 19516 KB Output is correct
40 Correct 112 ms 19520 KB Output is correct
41 Correct 113 ms 19536 KB Output is correct
42 Correct 113 ms 19496 KB Output is correct
43 Correct 119 ms 19568 KB Output is correct
44 Correct 110 ms 19444 KB Output is correct
45 Correct 107 ms 19516 KB Output is correct
46 Correct 108 ms 19540 KB Output is correct
47 Correct 704 ms 32804 KB Output is correct
48 Correct 2817 ms 63304 KB Output is correct
49 Correct 3216 ms 66460 KB Output is correct
50 Correct 3180 ms 66520 KB Output is correct
51 Correct 3070 ms 66608 KB Output is correct
52 Correct 3153 ms 66676 KB Output is correct
53 Correct 3058 ms 66620 KB Output is correct
54 Correct 2812 ms 66644 KB Output is correct
55 Correct 2960 ms 66772 KB Output is correct
56 Correct 2900 ms 66832 KB Output is correct
57 Correct 2925 ms 66752 KB Output is correct
58 Correct 2726 ms 66692 KB Output is correct
59 Correct 2440 ms 64884 KB Output is correct
60 Correct 2462 ms 64876 KB Output is correct
61 Correct 2487 ms 64780 KB Output is correct
62 Correct 2318 ms 64440 KB Output is correct
63 Correct 2597 ms 64448 KB Output is correct
64 Correct 2390 ms 64440 KB Output is correct
65 Correct 2025 ms 63984 KB Output is correct
66 Correct 2259 ms 64044 KB Output is correct
67 Correct 2104 ms 64052 KB Output is correct