답안 #674200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674200 2022-12-23T12:59:53 Z kirakaminski968 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1800 ms 62712 KB
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const int MAXN = 1e6 + 5;
int maxn[MAXN * 4 + 10], lazy[MAXN * 4 + 10];

void pushup(int rt) { maxn[rt] = max(maxn[rt << 1], maxn[rt << 1 | 1]); }
void pushdown(int rt) {
	if (lazy[rt]) {
		maxn[rt << 1] += lazy[rt], maxn[rt << 1 | 1] += lazy[rt];
		lazy[rt << 1] += lazy[rt], lazy[rt << 1 | 1] += lazy[rt];
		lazy[rt] = 0;
	}
}
void update(int L, int R, int I, int l = 1, int r = MAXN, int rt = 1) {
	if (L <= l && r <= R) {
		maxn[rt] += I, lazy[rt] += I;
		return;
	}
	int m = (l + r) / 2;
	pushdown(rt);
	if (L <= m) update(L, R, I, l, m, rt << 1);
	if (R > m) update(L, R, I, m + 1, r, rt << 1 | 1);
	pushup(rt);
}
int query(int L, int R, int l = 1, int r = MAXN, int rt = 1) {
	if (L <= l && r <= R)
		return maxn[rt];
	int m = (l + r) / 2, ans = -1e9, placed = 0;
	pushdown(rt);
	if (L <= m) {
		ans = query(L, R, l, m, rt << 1);
		placed = 1;
	}
	if (R > m) {
		if(placed) ans = max(ans, query(L, R, m + 1, r, rt << 1 | 1));
		else ans = query(L, R, m + 1, r, rt << 1 | 1);
	}
	return ans;
}
void p_update(int x, int I, int len = MAXN) {
	int v = query(x, x);
	update(x, x, I - v);
}

typedef pair<int, int> pr;
#define mp make_pair
pr pool[MAXN];
int tot;

struct BIT {
	int t[MAXN + 20];
	void update(int x, int I) {
		while (x <= MAXN)
			t[x] += I, x += x & -x;
	}
	int query(int x) {
		int ans = 0;
		while (x) ans += t[x], x -= x & -x;
		return ans;
	}
} T;

void compress(int &x, int id) {
	x = lower_bound(pool + 1, pool + tot + 1, mp(x, id)) - pool;
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V) {
	int Q = X.size(), N = A.size();
	std::vector<int> answer(Q);
	for (int i = 0; i < N; i++)
		pool[++tot] = mp(A[i], i);
	for (int i = 0; i < Q; i++)
		pool[++tot] = mp(V[i], X[i]);
	sort(pool + 1, pool + tot + 1);
	tot = unique(pool + 1, pool + tot + 1) - pool - 1;
	for (int i = 0; i < N; i++)
		compress(A[i], i), T.update(A[i], 1);
	for (int i = 0; i < Q; i++)
		compress(V[i], X[i]);
	for (int i = 0; i < 4 * MAXN + 10; i++)
		maxn[i] = -1e7;
	for (int i = 0; i < N; i++) {
		p_update(A[i], i - T.query(A[i] - 1));
	}
	for (int i = 0; i < Q; i++) {
		int src = A[X[i]];
		if (src == V[i]) {
			answer[i] = query(1, MAXN);
			continue;
		}
		T.update(src, -1);
		T.update(V[i], 1);
		p_update(src, -1e7);
		p_update(V[i], X[i] - T.query(V[i] - 1));
		if (src < V[i]) {
			if (src + 1 <= V[i] - 1) update(src + 1, V[i] - 1, 1);
		} else {
			if (V[i] + 1 <= src - 1) update(V[i] + 1, src - 1, -1);
		}
		A[X[i]] = V[i];
		answer[i] = query(1, MAXN);
	}
	return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16084 KB Output is correct
2 Correct 9 ms 16072 KB Output is correct
3 Correct 13 ms 16204 KB Output is correct
4 Correct 12 ms 16176 KB Output is correct
5 Correct 11 ms 16212 KB Output is correct
6 Correct 11 ms 16232 KB Output is correct
7 Correct 11 ms 16212 KB Output is correct
8 Correct 11 ms 16188 KB Output is correct
9 Correct 11 ms 16212 KB Output is correct
10 Correct 12 ms 16212 KB Output is correct
11 Correct 12 ms 16340 KB Output is correct
12 Correct 11 ms 16192 KB Output is correct
13 Correct 12 ms 16212 KB Output is correct
14 Correct 12 ms 16300 KB Output is correct
15 Correct 12 ms 16184 KB Output is correct
16 Correct 12 ms 16196 KB Output is correct
17 Correct 11 ms 16212 KB Output is correct
18 Correct 12 ms 16104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16084 KB Output is correct
2 Correct 9 ms 16072 KB Output is correct
3 Correct 13 ms 16204 KB Output is correct
4 Correct 12 ms 16176 KB Output is correct
5 Correct 11 ms 16212 KB Output is correct
6 Correct 11 ms 16232 KB Output is correct
7 Correct 11 ms 16212 KB Output is correct
8 Correct 11 ms 16188 KB Output is correct
9 Correct 11 ms 16212 KB Output is correct
10 Correct 12 ms 16212 KB Output is correct
11 Correct 12 ms 16340 KB Output is correct
12 Correct 11 ms 16192 KB Output is correct
13 Correct 12 ms 16212 KB Output is correct
14 Correct 12 ms 16300 KB Output is correct
15 Correct 12 ms 16184 KB Output is correct
16 Correct 12 ms 16196 KB Output is correct
17 Correct 11 ms 16212 KB Output is correct
18 Correct 12 ms 16104 KB Output is correct
19 Correct 25 ms 16672 KB Output is correct
20 Correct 26 ms 16688 KB Output is correct
21 Correct 25 ms 16772 KB Output is correct
22 Correct 25 ms 16704 KB Output is correct
23 Correct 24 ms 16716 KB Output is correct
24 Correct 25 ms 16712 KB Output is correct
25 Correct 27 ms 16692 KB Output is correct
26 Correct 25 ms 16636 KB Output is correct
27 Correct 24 ms 16692 KB Output is correct
28 Correct 25 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 16980 KB Output is correct
2 Correct 75 ms 18412 KB Output is correct
3 Correct 130 ms 19952 KB Output is correct
4 Correct 123 ms 19956 KB Output is correct
5 Correct 123 ms 19884 KB Output is correct
6 Correct 120 ms 19852 KB Output is correct
7 Correct 124 ms 19944 KB Output is correct
8 Correct 120 ms 19932 KB Output is correct
9 Correct 121 ms 19916 KB Output is correct
10 Correct 83 ms 19404 KB Output is correct
11 Correct 81 ms 19324 KB Output is correct
12 Correct 83 ms 19316 KB Output is correct
13 Correct 103 ms 19412 KB Output is correct
14 Correct 93 ms 19372 KB Output is correct
15 Correct 93 ms 19320 KB Output is correct
16 Correct 102 ms 19532 KB Output is correct
17 Correct 106 ms 19404 KB Output is correct
18 Correct 103 ms 19296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16084 KB Output is correct
2 Correct 9 ms 16072 KB Output is correct
3 Correct 13 ms 16204 KB Output is correct
4 Correct 12 ms 16176 KB Output is correct
5 Correct 11 ms 16212 KB Output is correct
6 Correct 11 ms 16232 KB Output is correct
7 Correct 11 ms 16212 KB Output is correct
8 Correct 11 ms 16188 KB Output is correct
9 Correct 11 ms 16212 KB Output is correct
10 Correct 12 ms 16212 KB Output is correct
11 Correct 12 ms 16340 KB Output is correct
12 Correct 11 ms 16192 KB Output is correct
13 Correct 12 ms 16212 KB Output is correct
14 Correct 12 ms 16300 KB Output is correct
15 Correct 12 ms 16184 KB Output is correct
16 Correct 12 ms 16196 KB Output is correct
17 Correct 11 ms 16212 KB Output is correct
18 Correct 12 ms 16104 KB Output is correct
19 Correct 25 ms 16672 KB Output is correct
20 Correct 26 ms 16688 KB Output is correct
21 Correct 25 ms 16772 KB Output is correct
22 Correct 25 ms 16704 KB Output is correct
23 Correct 24 ms 16716 KB Output is correct
24 Correct 25 ms 16712 KB Output is correct
25 Correct 27 ms 16692 KB Output is correct
26 Correct 25 ms 16636 KB Output is correct
27 Correct 24 ms 16692 KB Output is correct
28 Correct 25 ms 16724 KB Output is correct
29 Correct 28 ms 16980 KB Output is correct
30 Correct 75 ms 18412 KB Output is correct
31 Correct 130 ms 19952 KB Output is correct
32 Correct 123 ms 19956 KB Output is correct
33 Correct 123 ms 19884 KB Output is correct
34 Correct 120 ms 19852 KB Output is correct
35 Correct 124 ms 19944 KB Output is correct
36 Correct 120 ms 19932 KB Output is correct
37 Correct 121 ms 19916 KB Output is correct
38 Correct 83 ms 19404 KB Output is correct
39 Correct 81 ms 19324 KB Output is correct
40 Correct 83 ms 19316 KB Output is correct
41 Correct 103 ms 19412 KB Output is correct
42 Correct 93 ms 19372 KB Output is correct
43 Correct 93 ms 19320 KB Output is correct
44 Correct 102 ms 19532 KB Output is correct
45 Correct 106 ms 19404 KB Output is correct
46 Correct 103 ms 19296 KB Output is correct
47 Correct 405 ms 29628 KB Output is correct
48 Correct 1576 ms 58748 KB Output is correct
49 Correct 1713 ms 62496 KB Output is correct
50 Correct 1728 ms 62572 KB Output is correct
51 Correct 1717 ms 62428 KB Output is correct
52 Correct 1784 ms 62636 KB Output is correct
53 Correct 1800 ms 62460 KB Output is correct
54 Correct 1589 ms 62628 KB Output is correct
55 Correct 1734 ms 62616 KB Output is correct
56 Correct 1554 ms 62628 KB Output is correct
57 Correct 1617 ms 62712 KB Output is correct
58 Correct 1558 ms 62536 KB Output is correct
59 Correct 1508 ms 59920 KB Output is correct
60 Correct 1539 ms 59900 KB Output is correct
61 Correct 1511 ms 59952 KB Output is correct
62 Correct 1426 ms 59008 KB Output is correct
63 Correct 1436 ms 58944 KB Output is correct
64 Correct 1439 ms 58884 KB Output is correct
65 Correct 1399 ms 58132 KB Output is correct
66 Correct 1372 ms 58040 KB Output is correct
67 Correct 1404 ms 58048 KB Output is correct