답안 #1012329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012329 2024-07-01T23:46:49 Z d4xn Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1077 ms 78700 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#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 18 ms 47452 KB Output is correct
2 Correct 17 ms 47452 KB Output is correct
3 Correct 18 ms 47452 KB Output is correct
4 Correct 19 ms 47448 KB Output is correct
5 Correct 20 ms 47452 KB Output is correct
6 Correct 19 ms 47452 KB Output is correct
7 Correct 19 ms 47448 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 19 ms 47452 KB Output is correct
10 Correct 19 ms 47416 KB Output is correct
11 Correct 18 ms 47344 KB Output is correct
12 Correct 18 ms 47480 KB Output is correct
13 Correct 18 ms 47408 KB Output is correct
14 Correct 17 ms 47448 KB Output is correct
15 Correct 18 ms 47536 KB Output is correct
16 Correct 17 ms 47700 KB Output is correct
17 Correct 19 ms 47452 KB Output is correct
18 Correct 17 ms 47468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 47452 KB Output is correct
2 Correct 17 ms 47452 KB Output is correct
3 Correct 18 ms 47452 KB Output is correct
4 Correct 19 ms 47448 KB Output is correct
5 Correct 20 ms 47452 KB Output is correct
6 Correct 19 ms 47452 KB Output is correct
7 Correct 19 ms 47448 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 19 ms 47452 KB Output is correct
10 Correct 19 ms 47416 KB Output is correct
11 Correct 18 ms 47344 KB Output is correct
12 Correct 18 ms 47480 KB Output is correct
13 Correct 18 ms 47408 KB Output is correct
14 Correct 17 ms 47448 KB Output is correct
15 Correct 18 ms 47536 KB Output is correct
16 Correct 17 ms 47700 KB Output is correct
17 Correct 19 ms 47452 KB Output is correct
18 Correct 17 ms 47468 KB Output is correct
19 Correct 24 ms 47704 KB Output is correct
20 Correct 25 ms 47760 KB Output is correct
21 Correct 27 ms 47932 KB Output is correct
22 Correct 26 ms 47960 KB Output is correct
23 Correct 25 ms 47708 KB Output is correct
24 Correct 26 ms 47868 KB Output is correct
25 Correct 25 ms 47964 KB Output is correct
26 Correct 25 ms 47916 KB Output is correct
27 Correct 25 ms 47960 KB Output is correct
28 Correct 26 ms 47848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 47952 KB Output is correct
2 Correct 56 ms 49232 KB Output is correct
3 Correct 88 ms 50380 KB Output is correct
4 Correct 89 ms 50516 KB Output is correct
5 Correct 86 ms 50364 KB Output is correct
6 Correct 89 ms 50512 KB Output is correct
7 Correct 86 ms 50512 KB Output is correct
8 Correct 86 ms 50516 KB Output is correct
9 Correct 88 ms 50516 KB Output is correct
10 Correct 82 ms 50512 KB Output is correct
11 Correct 74 ms 50512 KB Output is correct
12 Correct 73 ms 50356 KB Output is correct
13 Correct 72 ms 50516 KB Output is correct
14 Correct 72 ms 50320 KB Output is correct
15 Correct 75 ms 50360 KB Output is correct
16 Correct 66 ms 50420 KB Output is correct
17 Correct 68 ms 50516 KB Output is correct
18 Correct 67 ms 50420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 47452 KB Output is correct
2 Correct 17 ms 47452 KB Output is correct
3 Correct 18 ms 47452 KB Output is correct
4 Correct 19 ms 47448 KB Output is correct
5 Correct 20 ms 47452 KB Output is correct
6 Correct 19 ms 47452 KB Output is correct
7 Correct 19 ms 47448 KB Output is correct
8 Correct 20 ms 47452 KB Output is correct
9 Correct 19 ms 47452 KB Output is correct
10 Correct 19 ms 47416 KB Output is correct
11 Correct 18 ms 47344 KB Output is correct
12 Correct 18 ms 47480 KB Output is correct
13 Correct 18 ms 47408 KB Output is correct
14 Correct 17 ms 47448 KB Output is correct
15 Correct 18 ms 47536 KB Output is correct
16 Correct 17 ms 47700 KB Output is correct
17 Correct 19 ms 47452 KB Output is correct
18 Correct 17 ms 47468 KB Output is correct
19 Correct 24 ms 47704 KB Output is correct
20 Correct 25 ms 47760 KB Output is correct
21 Correct 27 ms 47932 KB Output is correct
22 Correct 26 ms 47960 KB Output is correct
23 Correct 25 ms 47708 KB Output is correct
24 Correct 26 ms 47868 KB Output is correct
25 Correct 25 ms 47964 KB Output is correct
26 Correct 25 ms 47916 KB Output is correct
27 Correct 25 ms 47960 KB Output is correct
28 Correct 26 ms 47848 KB Output is correct
29 Correct 31 ms 47952 KB Output is correct
30 Correct 56 ms 49232 KB Output is correct
31 Correct 88 ms 50380 KB Output is correct
32 Correct 89 ms 50516 KB Output is correct
33 Correct 86 ms 50364 KB Output is correct
34 Correct 89 ms 50512 KB Output is correct
35 Correct 86 ms 50512 KB Output is correct
36 Correct 86 ms 50516 KB Output is correct
37 Correct 88 ms 50516 KB Output is correct
38 Correct 82 ms 50512 KB Output is correct
39 Correct 74 ms 50512 KB Output is correct
40 Correct 73 ms 50356 KB Output is correct
41 Correct 72 ms 50516 KB Output is correct
42 Correct 72 ms 50320 KB Output is correct
43 Correct 75 ms 50360 KB Output is correct
44 Correct 66 ms 50420 KB Output is correct
45 Correct 68 ms 50516 KB Output is correct
46 Correct 67 ms 50420 KB Output is correct
47 Correct 277 ms 56400 KB Output is correct
48 Correct 975 ms 76296 KB Output is correct
49 Correct 1060 ms 78652 KB Output is correct
50 Correct 1051 ms 78672 KB Output is correct
51 Correct 1077 ms 78672 KB Output is correct
52 Correct 1056 ms 78672 KB Output is correct
53 Correct 1037 ms 78676 KB Output is correct
54 Correct 978 ms 78624 KB Output is correct
55 Correct 1010 ms 78676 KB Output is correct
56 Correct 961 ms 78692 KB Output is correct
57 Correct 1032 ms 78564 KB Output is correct
58 Correct 929 ms 78648 KB Output is correct
59 Correct 939 ms 78572 KB Output is correct
60 Correct 861 ms 78500 KB Output is correct
61 Correct 872 ms 78672 KB Output is correct
62 Correct 878 ms 78500 KB Output is correct
63 Correct 857 ms 78700 KB Output is correct
64 Correct 846 ms 78676 KB Output is correct
65 Correct 827 ms 78504 KB Output is correct
66 Correct 820 ms 78676 KB Output is correct
67 Correct 827 ms 78696 KB Output is correct