답안 #163513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163513 2019-11-13T16:21:42 Z NachoLibre Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
5398 ms 160484 KB
#include <bits/stdc++.h>
using namespace std;
#include "bubblesort2.h"

struct dor {
	dor *l, *r;
	int dt, sh;
	dor() {
		l = r = NULL;
		dt = sh = 0;
	}

	int sd() {
		return dt + sh;
	}

	void sheps() {
		if(l == NULL) l = new dor();
		if(r == NULL) r = new dor();
		l->sh += sh;
		r->sh += sh;
		sh = 0;
	}

	void pump() {
		dt = max(l->sd(), r->sd());
	}
} *rt = new dor();

void gnk(int l, int r, int sl, int sr, int vl, dor *&t) {
	if(l > sr || r < sl) return;
	if(l >= sl && r <= sr) {
		t->sh += vl;
		return;
	}
	t->sheps();
	gnk(l, (l + r) / 2, sl, sr, vl, t->l);
	gnk((l + r) / 2 + 1, r, sl, sr, vl, t->r);
	t->pump();
}

int rwi(int l, int r, int si, dor *&t) {
	if(l == r) return t->sd();
	if((l + r) / 2 >= si) return rwi(l, (l + r) / 2, si, t->l);
	return rwi((l + r) / 2 + 1, r, si, t->r);
}

const int inf = 100000000;

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
	int n = a.size();
	int q = x.size();
	vector<int> fp;
	vector<pair<int, int> > u;
	map<pair<int, int>, int> ma;
	for(int i = 0; i < n; ++i) {
		u.push_back({a[i], i});
	}
	for(int i = 0; i < q; ++i) {
		x[i];
		u.push_back({v[i], x[i]});
	}
	sort(u.begin(), u.end());
	for(int i = 0; i < n + q; ++i) {
		ma[u[i]] = i + 1;
	}
	gnk(1, n + q, 1, n + q, -inf, rt);
	for(int i = 0; i < n; ++i) {
		int rae = ma[{a[i], i}];
		gnk(1, n + q, rae, rae, inf + i, rt);
		gnk(1, n + q, rae + 1, n + q, -1, rt);
	}
	int rvu;
	//for(int j = 1; j <= n + q; ++j) cout << rwi(1, n + q, j, rt) << " ";
	//cout << endl;
	for(int i = 0; i < q; ++i) {
		int sdn = ma[{a[x[i]], x[i]}], sad = ma[{v[i], x[i]}];
		//cout << sdn << " " << sad << endl;
		rvu = 1;
		a[x[i]] = v[i];
		gnk(1, n + q, sdn, sdn, -inf - x[i], rt);
		gnk(1, n + q, sad, sad, inf + x[i], rt);
		if(sdn > sad) swap(sdn, sad), rvu = -1;
		//gnk(1, n + q, sdn, sdn, -inf - x[i], rt);
		if(sad - sdn >= 2) gnk(1, n + q, sdn + 1, sad - 1, rvu, rt);
		//gnk(1, n + q, sad, sad, inf + x[i], rt);
		int tp = rt->sd();
		fp.push_back(tp);
		//for(int j = 1; j <= n + q; ++j) cout << rwi(1, n + q, j, rt) << " ";
		//cout << endl;
	}
	return fp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 15 ms 1016 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 9 ms 1000 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 9 ms 1016 KB Output is correct
10 Correct 9 ms 892 KB Output is correct
11 Correct 10 ms 888 KB Output is correct
12 Correct 8 ms 888 KB Output is correct
13 Correct 8 ms 888 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 8 ms 888 KB Output is correct
17 Correct 8 ms 888 KB Output is correct
18 Correct 8 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 15 ms 1016 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 9 ms 1000 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 9 ms 1016 KB Output is correct
10 Correct 9 ms 892 KB Output is correct
11 Correct 10 ms 888 KB Output is correct
12 Correct 8 ms 888 KB Output is correct
13 Correct 8 ms 888 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 8 ms 888 KB Output is correct
17 Correct 8 ms 888 KB Output is correct
18 Correct 8 ms 888 KB Output is correct
19 Correct 31 ms 2556 KB Output is correct
20 Correct 36 ms 2920 KB Output is correct
21 Correct 34 ms 2940 KB Output is correct
22 Correct 35 ms 2808 KB Output is correct
23 Correct 70 ms 2680 KB Output is correct
24 Correct 32 ms 2684 KB Output is correct
25 Correct 32 ms 2680 KB Output is correct
26 Correct 33 ms 2680 KB Output is correct
27 Correct 32 ms 2544 KB Output is correct
28 Correct 31 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 4472 KB Output is correct
2 Correct 168 ms 10172 KB Output is correct
3 Correct 316 ms 15844 KB Output is correct
4 Correct 317 ms 15728 KB Output is correct
5 Correct 306 ms 15564 KB Output is correct
6 Correct 310 ms 15596 KB Output is correct
7 Correct 299 ms 15468 KB Output is correct
8 Correct 308 ms 15548 KB Output is correct
9 Correct 307 ms 15568 KB Output is correct
10 Correct 200 ms 11884 KB Output is correct
11 Correct 197 ms 11884 KB Output is correct
12 Correct 199 ms 11852 KB Output is correct
13 Correct 194 ms 11372 KB Output is correct
14 Correct 192 ms 11380 KB Output is correct
15 Correct 193 ms 11456 KB Output is correct
16 Correct 199 ms 10808 KB Output is correct
17 Correct 203 ms 10732 KB Output is correct
18 Correct 184 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 15 ms 1016 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 9 ms 1000 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 9 ms 1016 KB Output is correct
10 Correct 9 ms 892 KB Output is correct
11 Correct 10 ms 888 KB Output is correct
12 Correct 8 ms 888 KB Output is correct
13 Correct 8 ms 888 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 8 ms 888 KB Output is correct
17 Correct 8 ms 888 KB Output is correct
18 Correct 8 ms 888 KB Output is correct
19 Correct 31 ms 2556 KB Output is correct
20 Correct 36 ms 2920 KB Output is correct
21 Correct 34 ms 2940 KB Output is correct
22 Correct 35 ms 2808 KB Output is correct
23 Correct 70 ms 2680 KB Output is correct
24 Correct 32 ms 2684 KB Output is correct
25 Correct 32 ms 2680 KB Output is correct
26 Correct 33 ms 2680 KB Output is correct
27 Correct 32 ms 2544 KB Output is correct
28 Correct 31 ms 2552 KB Output is correct
29 Correct 51 ms 4472 KB Output is correct
30 Correct 168 ms 10172 KB Output is correct
31 Correct 316 ms 15844 KB Output is correct
32 Correct 317 ms 15728 KB Output is correct
33 Correct 306 ms 15564 KB Output is correct
34 Correct 310 ms 15596 KB Output is correct
35 Correct 299 ms 15468 KB Output is correct
36 Correct 308 ms 15548 KB Output is correct
37 Correct 307 ms 15568 KB Output is correct
38 Correct 200 ms 11884 KB Output is correct
39 Correct 197 ms 11884 KB Output is correct
40 Correct 199 ms 11852 KB Output is correct
41 Correct 194 ms 11372 KB Output is correct
42 Correct 192 ms 11380 KB Output is correct
43 Correct 193 ms 11456 KB Output is correct
44 Correct 199 ms 10808 KB Output is correct
45 Correct 203 ms 10732 KB Output is correct
46 Correct 184 ms 10836 KB Output is correct
47 Correct 1213 ms 48148 KB Output is correct
48 Correct 4760 ms 146392 KB Output is correct
49 Correct 5398 ms 160228 KB Output is correct
50 Correct 5365 ms 160228 KB Output is correct
51 Correct 5113 ms 160260 KB Output is correct
52 Correct 5154 ms 160212 KB Output is correct
53 Correct 5174 ms 160100 KB Output is correct
54 Correct 4803 ms 160284 KB Output is correct
55 Correct 5242 ms 160484 KB Output is correct
56 Correct 4820 ms 160376 KB Output is correct
57 Correct 5323 ms 160312 KB Output is correct
58 Correct 4794 ms 160432 KB Output is correct
59 Correct 4189 ms 150404 KB Output is correct
60 Correct 4357 ms 150356 KB Output is correct
61 Correct 4231 ms 150328 KB Output is correct
62 Correct 3974 ms 145188 KB Output is correct
63 Correct 3964 ms 145336 KB Output is correct
64 Correct 3971 ms 145364 KB Output is correct
65 Correct 3675 ms 140232 KB Output is correct
66 Correct 3667 ms 140208 KB Output is correct
67 Correct 3623 ms 140276 KB Output is correct