답안 #380926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380926 2021-03-23T15:49:36 Z qwerty234 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3735 ms 166824 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#define ll long long
#define fi first
#define se second
#define pb push_back

using namespace std;
const int MAXN = 1e6 + 10, inf = 1e9, inff = 1e7;

int t[4 * MAXN], add[4 * MAXN], m;
vector <set<int>> s;

void build(int v, int tl, int tr) {
	add[v] = inf;
	t[v] = 0;
	if (tl == tr)
		return;
	int tm = (tl + tr)>>1;
	build((v << 1), tl, tm);
	build(((v << 1)|1), tm + 1, tr);
}

void push(int v, int tl, int tr) {
	if (tl == tr || add[v] == inf)
		return;
	t[(v << 1)] += add[v];
	t[((v << 1)|1)] += add[v];
	if (add[(v << 1)] == inf)
		add[(v << 1)] = add[v];
	else
		add[(v << 1)] += add[v];
	if (add[((v << 1)|1)] == inf)
		add[((v << 1)|1)] = add[v];
	else
		add[((v << 1)|1)] += add[v];
	add[v] = inf;
}

void upd(int v, int tl, int tr, int l, int r, int val) {
	if (r < tl || tr < l)
		return;
	if (l <= tl && tr <= r) {
		t[v] += val;
		if (add[v] == inf)
			add[v] = val;
		else
			add[v] += val;
		return;
	}
	int tm = (tl + tr)>>1;
	push(v, tl, tr);
	upd((v << 1), tl, tm, l, r, val);
	upd(((v << 1)|1), tm + 1, tr, l, r, val);
	t[v] = max(t[(v << 1)], t[((v << 1)|1)]);
}

int get(int v, int tl, int tr, int l, int r) {
	if (r < tl || tr < l)
		return -inff;
	push(v, tl, tr);
	if (l <= tl && tr <= r)
		return t[v];
	int tm = (tl + tr)>>1;
	return max(get((v << 1), tl, tm, l, r), get(((v << 1)|1), tm + 1, tr, l, r));
}

void addd(int i, int x) {
	int mx1 = -*s[x].begin();
	s[x].insert(-i);
	int mx2 = -*s[x].begin();
	upd(1, 0, m - 1, x, x, -mx1 + mx2);
	upd(1, 0, m - 1, x, m - 1, -1);
}

void del(int i, int x) {
	int mx1 = -*s[x].begin();
	s[x].erase(-i);
	int mx2 = -*s[x].begin();
	upd(1, 0, m - 1, x, x, -mx1 + mx2);
	upd(1, 0, m - 1, x, m - 1, 1);
}

vector <int> countScans(vector <int> a, vector <int> x, vector <int> v) {
	int n = a.size(), q = x.size();
	vector <int> ar = {};
	for (int i = 0; i < n; i++) ar.pb(a[i]);
	for (int i = 0; i < q; i++) ar.pb(v[i]);
	sort(ar.begin(), ar.end());
	m = unique(ar.begin(), ar.end()) - ar.begin();
	for (int i = 0; i < n; i++)
		a[i] = lower_bound(ar.begin(), ar.begin() + m, a[i]) - ar.begin();
	for (int i = 0; i < q; i++)
		v[i] = lower_bound(ar.begin(), ar.begin() + m, v[i]) - ar.begin();
	build(1, 0, m - 1);
	s.resize(m);
	for (int i = 0; i < m; i++) {
		s[i].clear();
		s[i].insert(inff);
	}
	for (int i = 0; i < m; i++)
		upd(1, 0, m - 1, i, i, -*s[i].begin());
	for (int i = 0; i < n; i++)
		addd(i, a[i]);
	vector <int> ans;
	for (int i = 0; i < q; i++) {
		del(x[i], a[x[i]]);
		addd(x[i], v[i]);
		a[x[i]] = v[i];
		ans.pb(get(1, 0, m - 1, 0, m - 1) + 1);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 7 ms 1004 KB Output is correct
4 Correct 7 ms 1004 KB Output is correct
5 Correct 7 ms 1004 KB Output is correct
6 Correct 7 ms 1004 KB Output is correct
7 Correct 7 ms 1004 KB Output is correct
8 Correct 7 ms 1004 KB Output is correct
9 Correct 9 ms 1004 KB Output is correct
10 Correct 6 ms 1004 KB Output is correct
11 Correct 7 ms 1004 KB Output is correct
12 Correct 7 ms 1004 KB Output is correct
13 Correct 6 ms 876 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 6 ms 876 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 7 ms 1004 KB Output is correct
4 Correct 7 ms 1004 KB Output is correct
5 Correct 7 ms 1004 KB Output is correct
6 Correct 7 ms 1004 KB Output is correct
7 Correct 7 ms 1004 KB Output is correct
8 Correct 7 ms 1004 KB Output is correct
9 Correct 9 ms 1004 KB Output is correct
10 Correct 6 ms 1004 KB Output is correct
11 Correct 7 ms 1004 KB Output is correct
12 Correct 7 ms 1004 KB Output is correct
13 Correct 6 ms 876 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 6 ms 876 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 30 ms 2796 KB Output is correct
20 Correct 36 ms 3048 KB Output is correct
21 Correct 30 ms 3052 KB Output is correct
22 Correct 30 ms 3052 KB Output is correct
23 Correct 33 ms 2796 KB Output is correct
24 Correct 28 ms 2816 KB Output is correct
25 Correct 28 ms 2668 KB Output is correct
26 Correct 28 ms 2668 KB Output is correct
27 Correct 27 ms 2668 KB Output is correct
28 Correct 25 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2028 KB Output is correct
2 Correct 60 ms 3684 KB Output is correct
3 Correct 109 ms 5348 KB Output is correct
4 Correct 106 ms 5220 KB Output is correct
5 Correct 103 ms 5220 KB Output is correct
6 Correct 115 ms 5348 KB Output is correct
7 Correct 112 ms 5348 KB Output is correct
8 Correct 128 ms 5348 KB Output is correct
9 Correct 106 ms 5348 KB Output is correct
10 Correct 85 ms 5476 KB Output is correct
11 Correct 84 ms 5348 KB Output is correct
12 Correct 92 ms 5348 KB Output is correct
13 Correct 84 ms 5348 KB Output is correct
14 Correct 83 ms 5348 KB Output is correct
15 Correct 85 ms 5344 KB Output is correct
16 Correct 75 ms 5348 KB Output is correct
17 Correct 92 ms 5348 KB Output is correct
18 Correct 79 ms 5348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 7 ms 1004 KB Output is correct
4 Correct 7 ms 1004 KB Output is correct
5 Correct 7 ms 1004 KB Output is correct
6 Correct 7 ms 1004 KB Output is correct
7 Correct 7 ms 1004 KB Output is correct
8 Correct 7 ms 1004 KB Output is correct
9 Correct 9 ms 1004 KB Output is correct
10 Correct 6 ms 1004 KB Output is correct
11 Correct 7 ms 1004 KB Output is correct
12 Correct 7 ms 1004 KB Output is correct
13 Correct 6 ms 876 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 6 ms 876 KB Output is correct
18 Correct 6 ms 876 KB Output is correct
19 Correct 30 ms 2796 KB Output is correct
20 Correct 36 ms 3048 KB Output is correct
21 Correct 30 ms 3052 KB Output is correct
22 Correct 30 ms 3052 KB Output is correct
23 Correct 33 ms 2796 KB Output is correct
24 Correct 28 ms 2816 KB Output is correct
25 Correct 28 ms 2668 KB Output is correct
26 Correct 28 ms 2668 KB Output is correct
27 Correct 27 ms 2668 KB Output is correct
28 Correct 25 ms 2668 KB Output is correct
29 Correct 20 ms 2028 KB Output is correct
30 Correct 60 ms 3684 KB Output is correct
31 Correct 109 ms 5348 KB Output is correct
32 Correct 106 ms 5220 KB Output is correct
33 Correct 103 ms 5220 KB Output is correct
34 Correct 115 ms 5348 KB Output is correct
35 Correct 112 ms 5348 KB Output is correct
36 Correct 128 ms 5348 KB Output is correct
37 Correct 106 ms 5348 KB Output is correct
38 Correct 85 ms 5476 KB Output is correct
39 Correct 84 ms 5348 KB Output is correct
40 Correct 92 ms 5348 KB Output is correct
41 Correct 84 ms 5348 KB Output is correct
42 Correct 83 ms 5348 KB Output is correct
43 Correct 85 ms 5344 KB Output is correct
44 Correct 75 ms 5348 KB Output is correct
45 Correct 92 ms 5348 KB Output is correct
46 Correct 79 ms 5348 KB Output is correct
47 Correct 899 ms 53852 KB Output is correct
48 Correct 3260 ms 152840 KB Output is correct
49 Correct 3666 ms 166824 KB Output is correct
50 Correct 3626 ms 166740 KB Output is correct
51 Correct 3607 ms 166652 KB Output is correct
52 Correct 3615 ms 166732 KB Output is correct
53 Correct 3735 ms 166648 KB Output is correct
54 Correct 3354 ms 166676 KB Output is correct
55 Correct 3494 ms 166732 KB Output is correct
56 Correct 3385 ms 166740 KB Output is correct
57 Correct 3425 ms 166780 KB Output is correct
58 Correct 3262 ms 166668 KB Output is correct
59 Correct 2952 ms 153712 KB Output is correct
60 Correct 2929 ms 153756 KB Output is correct
61 Correct 2948 ms 153812 KB Output is correct
62 Correct 2800 ms 147692 KB Output is correct
63 Correct 2843 ms 147712 KB Output is correct
64 Correct 2816 ms 147796 KB Output is correct
65 Correct 2646 ms 141716 KB Output is correct
66 Correct 2656 ms 141780 KB Output is correct
67 Correct 2623 ms 141780 KB Output is correct