답안 #1012327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012327 2024-07-01T23:46:11 Z d4xn Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1172 ms 91732 KB
#pragma GCC optimize ("Ofast")
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

const int N = 5e5, inf = 1e9;

int n, q, a[N], x[N], v[N], seg[2][N*8], laz[N*8];
vector<int> b, ans;
vector<pair<int, int>> comp;

void pushDown(int p) {
	for (int h : {p*2, p*2+1}) {
		seg[0][h] += laz[p];
		laz[h] += laz[p];
	}
	laz[p] = 0;
}

void updateSet(int idx, int x, int p=1, int l=0, int r=n+q-1) {
	if (l == r) {
		seg[0][p] = x;
		if (x == -inf) seg[1][p] = 0;
		else seg[1][p] = 1;
		return;
	}
	pushDown(p);
	int mid = (l+r) >> 1;

	if (idx <= mid) updateSet(idx, x, p*2, l, mid);
	else updateSet(idx, x, p*2+1, mid+1, r);

	seg[0][p] = max(seg[0][p*2], seg[0][p*2+1]);
	seg[1][p] = seg[1][p*2] + seg[1][p*2+1];
}

void updateSum(int idx, int x, int p=1, int l=0, int r=n+q-1) {
	if (idx <= l) {
		seg[0][p] += x;
		laz[p] += x;
		return;
	}
	pushDown(p);
	int mid = (l+r) >> 1;

	if (idx <= mid) updateSum(idx, x, p*2, l, mid);
	updateSum(idx, x, p*2+1, mid+1, r);

	seg[0][p] = max(seg[0][p*2], seg[0][p*2+1]);
	seg[1][p] = seg[1][p*2] + seg[1][p*2+1];
}

int queryCount(int idx, int p=1, int l=0, int r=n+q-1) {
	if (r <= idx) {
		return seg[1][p];
	}
	pushDown(p);
	int mid = (l+r) >> 1;

	int x = queryCount(idx, p*2, l, mid);
	if (mid+1 <= idx) x += queryCount(idx, p*2+1, mid+1, r);

	return x;
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	n = A.size();
	q = X.size();

	comp.resize(n+q);
	for (int i = 0; i < n; i++) {
		a[i] = A[i];
		comp[i] = make_pair(a[i], i);
	}

	for (int i = 0; i < q; i++) {
		x[i] = X[i];
		v[i] = V[i];
		comp[n+i] = make_pair(v[i], x[i]);
	}
	sort(all(comp));
	comp.erase(unique(all(comp)), comp.end());

	b.resize(n);
	for (int i = 0; i < n; i++) {
		a[i] = lower_bound(all(comp), make_pair(a[i], i)) - comp.begin();
		b[i] = a[i];
	}
	sort(all(b));

	for (int i = 0; i < q; i++) {
		v[i] = lower_bound(all(comp), make_pair(v[i], x[i])) - comp.begin();
	}

	memset(seg, 0, sizeof(seg));
	memset(laz, 0, sizeof(laz));
	for (int i = 0; i < n; i++) {
		int idx = lower_bound(all(b), a[i]) - b.begin();
		updateSet(a[i], i - idx);
	}

	ans.resize(q);
	for (int i = 0; i < q; i++) {
		updateSum(a[x[i]], 1);
		updateSet(a[x[i]], -inf);

		int idx = queryCount(v[i]);
		updateSum(v[i], -1);
		updateSet(v[i], x[i] - idx);

		ans[i] = seg[0][1];
		a[x[i]] = v[i];
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 21 ms 47560 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 20 ms 47472 KB Output is correct
6 Correct 25 ms 47468 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 20 ms 47576 KB Output is correct
10 Correct 20 ms 47448 KB Output is correct
11 Correct 21 ms 47448 KB Output is correct
12 Correct 28 ms 47452 KB Output is correct
13 Correct 20 ms 47356 KB Output is correct
14 Correct 18 ms 47452 KB Output is correct
15 Correct 19 ms 47452 KB Output is correct
16 Correct 19 ms 47416 KB Output is correct
17 Correct 18 ms 47452 KB Output is correct
18 Correct 18 ms 47452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 21 ms 47560 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 20 ms 47472 KB Output is correct
6 Correct 25 ms 47468 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 20 ms 47576 KB Output is correct
10 Correct 20 ms 47448 KB Output is correct
11 Correct 21 ms 47448 KB Output is correct
12 Correct 28 ms 47452 KB Output is correct
13 Correct 20 ms 47356 KB Output is correct
14 Correct 18 ms 47452 KB Output is correct
15 Correct 19 ms 47452 KB Output is correct
16 Correct 19 ms 47416 KB Output is correct
17 Correct 18 ms 47452 KB Output is correct
18 Correct 18 ms 47452 KB Output is correct
19 Correct 26 ms 47964 KB Output is correct
20 Correct 29 ms 48132 KB Output is correct
21 Correct 28 ms 47952 KB Output is correct
22 Correct 27 ms 47960 KB Output is correct
23 Correct 27 ms 47956 KB Output is correct
24 Correct 29 ms 47956 KB Output is correct
25 Correct 27 ms 47964 KB Output is correct
26 Correct 27 ms 47972 KB Output is correct
27 Correct 28 ms 48048 KB Output is correct
28 Correct 27 ms 47956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 48220 KB Output is correct
2 Correct 58 ms 49592 KB Output is correct
3 Correct 91 ms 51028 KB Output is correct
4 Correct 96 ms 51024 KB Output is correct
5 Correct 92 ms 50900 KB Output is correct
6 Correct 97 ms 50992 KB Output is correct
7 Correct 86 ms 51028 KB Output is correct
8 Correct 91 ms 51024 KB Output is correct
9 Correct 111 ms 50960 KB Output is correct
10 Correct 76 ms 51028 KB Output is correct
11 Correct 82 ms 51100 KB Output is correct
12 Correct 75 ms 51032 KB Output is correct
13 Correct 74 ms 51032 KB Output is correct
14 Correct 81 ms 50944 KB Output is correct
15 Correct 84 ms 51000 KB Output is correct
16 Correct 70 ms 51016 KB Output is correct
17 Correct 69 ms 51028 KB Output is correct
18 Correct 81 ms 51024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 21 ms 47560 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 20 ms 47472 KB Output is correct
6 Correct 25 ms 47468 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 20 ms 47576 KB Output is correct
10 Correct 20 ms 47448 KB Output is correct
11 Correct 21 ms 47448 KB Output is correct
12 Correct 28 ms 47452 KB Output is correct
13 Correct 20 ms 47356 KB Output is correct
14 Correct 18 ms 47452 KB Output is correct
15 Correct 19 ms 47452 KB Output is correct
16 Correct 19 ms 47416 KB Output is correct
17 Correct 18 ms 47452 KB Output is correct
18 Correct 18 ms 47452 KB Output is correct
19 Correct 26 ms 47964 KB Output is correct
20 Correct 29 ms 48132 KB Output is correct
21 Correct 28 ms 47952 KB Output is correct
22 Correct 27 ms 47960 KB Output is correct
23 Correct 27 ms 47956 KB Output is correct
24 Correct 29 ms 47956 KB Output is correct
25 Correct 27 ms 47964 KB Output is correct
26 Correct 27 ms 47972 KB Output is correct
27 Correct 28 ms 48048 KB Output is correct
28 Correct 27 ms 47956 KB Output is correct
29 Correct 35 ms 48220 KB Output is correct
30 Correct 58 ms 49592 KB Output is correct
31 Correct 91 ms 51028 KB Output is correct
32 Correct 96 ms 51024 KB Output is correct
33 Correct 92 ms 50900 KB Output is correct
34 Correct 97 ms 50992 KB Output is correct
35 Correct 86 ms 51028 KB Output is correct
36 Correct 91 ms 51024 KB Output is correct
37 Correct 111 ms 50960 KB Output is correct
38 Correct 76 ms 51028 KB Output is correct
39 Correct 82 ms 51100 KB Output is correct
40 Correct 75 ms 51032 KB Output is correct
41 Correct 74 ms 51032 KB Output is correct
42 Correct 81 ms 50944 KB Output is correct
43 Correct 84 ms 51000 KB Output is correct
44 Correct 70 ms 51016 KB Output is correct
45 Correct 69 ms 51028 KB Output is correct
46 Correct 81 ms 51024 KB Output is correct
47 Correct 307 ms 60240 KB Output is correct
48 Correct 1012 ms 88156 KB Output is correct
49 Correct 1172 ms 91512 KB Output is correct
50 Correct 1071 ms 91544 KB Output is correct
51 Correct 1056 ms 91424 KB Output is correct
52 Correct 1034 ms 91544 KB Output is correct
53 Correct 1087 ms 91468 KB Output is correct
54 Correct 923 ms 91728 KB Output is correct
55 Correct 1006 ms 91728 KB Output is correct
56 Correct 920 ms 91732 KB Output is correct
57 Correct 1050 ms 91588 KB Output is correct
58 Correct 902 ms 91728 KB Output is correct
59 Correct 864 ms 90388 KB Output is correct
60 Correct 855 ms 90220 KB Output is correct
61 Correct 858 ms 90192 KB Output is correct
62 Correct 851 ms 90324 KB Output is correct
63 Correct 829 ms 90188 KB Output is correct
64 Correct 830 ms 90104 KB Output is correct
65 Correct 789 ms 89936 KB Output is correct
66 Correct 850 ms 89940 KB Output is correct
67 Correct 822 ms 89940 KB Output is correct