Submission #99324

# Submission time Handle Problem Language Result Execution time Memory
99324 2019-03-02T15:13:29 Z youngyojun Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
3372 ms 66844 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define INF (0x3f3f3f3f)
using namespace std;
typedef pair<int, int> pii;

const int MAXN = 500055;
const int MAXQ = 500055;
const int MAXC = MAXN+MAXQ;

struct SEG {
	SEG() { init(); }
	int ds[MAXC*4], dmx[MAXC*4];

	void init() {
		fill(dmx, dmx+MAXC*4, -INF);
	}

	void prop(int i, int s, int e) {
		if(!ds[i]) return;
		if(s != e) {
			ds[i<<1] += ds[i];
			ds[i<<1|1] += ds[i];
		}
		dmx[i] += ds[i];
		ds[i] = 0;
	}
	void cal(int i) {
		dmx[i] = max(dmx[i<<1], dmx[i<<1|1]);
	}

	void upd(int i, int s, int e, int p, int q, int r) {
		prop(i, s, e);
		if(q < p || e < p || q < s) return;
		if(p <= s && e <= q) {
			ds[i] += r;
			prop(i, s, e);
			return;
		}
		int m = (s+e) >> 1;
		upd(i<<1, s, m, p, q, r);
		upd(i<<1|1, m+1, e, p, q, r);
		cal(i);
	}
	int get() { return dmx[1]; }
} seg;

vector<pii> PV;
int A[MAXN], B[MAXQ], C[MAXQ];

int Ans[MAXQ];
int N, Q, L;

void solve() {
	for(int i = 0; i < N; i++) PV.eb(A[i], i);
	for(int i = 0; i < Q; i++) PV.eb(B[i], C[i]);
	sorv(PV); univ(PV);
	L = sz(PV);

	for(int i = 0, j; i < N; i++) {
		j = int(lower_bound(allv(PV), pii(A[i], i)) - PV.begin());
		seg.upd(1, 0, L-1, j, j, INF+i);
		seg.upd(1, 0, L-1, j+1, L-1, -1);
		A[i] = j;
	}
	for(int i = 0, j, k; i < Q; i++) {
		j = int(lower_bound(allv(PV), pii(B[i], C[i])) - PV.begin());
		k = A[C[i]];
		seg.upd(1, 0, L-1, k, k, -INF-C[i]);
		seg.upd(1, 0, L-1, k+1, L-1, 1);
		seg.upd(1, 0, L-1, j, j, INF+C[i]);
		seg.upd(1, 0, L-1, j+1, L-1, -1);
		A[C[i]] = j;
		Ans[i] = seg.get();
	}
}

std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V) {
	::N = sz(A); ::Q = sz(X);
	for(int i = 0; i < N; i++) ::A[i] = A[i];
	for(int i = 0; i < Q; i++) {
		::C[i] = X[i];
		::B[i] = V[i];
	}
	solve();
	vector<int> ret(Q);
	for(int i = 0; i < Q; i++) ret[i] = Ans[i];
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 16128 KB Output is correct
2 Correct 21 ms 16128 KB Output is correct
3 Correct 20 ms 16248 KB Output is correct
4 Correct 26 ms 16256 KB Output is correct
5 Correct 20 ms 16304 KB Output is correct
6 Correct 20 ms 16256 KB Output is correct
7 Correct 23 ms 16224 KB Output is correct
8 Correct 16 ms 16256 KB Output is correct
9 Correct 20 ms 16256 KB Output is correct
10 Correct 22 ms 16384 KB Output is correct
11 Correct 18 ms 16256 KB Output is correct
12 Correct 20 ms 16256 KB Output is correct
13 Correct 20 ms 16256 KB Output is correct
14 Correct 23 ms 16264 KB Output is correct
15 Correct 22 ms 16248 KB Output is correct
16 Correct 21 ms 16256 KB Output is correct
17 Correct 20 ms 16256 KB Output is correct
18 Correct 21 ms 16256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 16128 KB Output is correct
2 Correct 21 ms 16128 KB Output is correct
3 Correct 20 ms 16248 KB Output is correct
4 Correct 26 ms 16256 KB Output is correct
5 Correct 20 ms 16304 KB Output is correct
6 Correct 20 ms 16256 KB Output is correct
7 Correct 23 ms 16224 KB Output is correct
8 Correct 16 ms 16256 KB Output is correct
9 Correct 20 ms 16256 KB Output is correct
10 Correct 22 ms 16384 KB Output is correct
11 Correct 18 ms 16256 KB Output is correct
12 Correct 20 ms 16256 KB Output is correct
13 Correct 20 ms 16256 KB Output is correct
14 Correct 23 ms 16264 KB Output is correct
15 Correct 22 ms 16248 KB Output is correct
16 Correct 21 ms 16256 KB Output is correct
17 Correct 20 ms 16256 KB Output is correct
18 Correct 21 ms 16256 KB Output is correct
19 Correct 36 ms 16892 KB Output is correct
20 Correct 35 ms 17016 KB Output is correct
21 Correct 36 ms 16896 KB Output is correct
22 Correct 36 ms 17016 KB Output is correct
23 Correct 37 ms 16896 KB Output is correct
24 Correct 44 ms 16896 KB Output is correct
25 Correct 44 ms 16956 KB Output is correct
26 Correct 35 ms 16896 KB Output is correct
27 Correct 40 ms 16888 KB Output is correct
28 Correct 34 ms 16896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 17140 KB Output is correct
2 Correct 110 ms 18672 KB Output is correct
3 Correct 181 ms 20588 KB Output is correct
4 Correct 179 ms 20728 KB Output is correct
5 Correct 171 ms 20452 KB Output is correct
6 Correct 179 ms 20592 KB Output is correct
7 Correct 158 ms 20556 KB Output is correct
8 Correct 142 ms 20588 KB Output is correct
9 Correct 169 ms 20664 KB Output is correct
10 Correct 170 ms 20220 KB Output is correct
11 Correct 123 ms 20092 KB Output is correct
12 Correct 133 ms 20080 KB Output is correct
13 Correct 123 ms 20332 KB Output is correct
14 Correct 131 ms 20204 KB Output is correct
15 Correct 118 ms 20204 KB Output is correct
16 Correct 119 ms 20100 KB Output is correct
17 Correct 125 ms 20204 KB Output is correct
18 Correct 113 ms 20076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 16128 KB Output is correct
2 Correct 21 ms 16128 KB Output is correct
3 Correct 20 ms 16248 KB Output is correct
4 Correct 26 ms 16256 KB Output is correct
5 Correct 20 ms 16304 KB Output is correct
6 Correct 20 ms 16256 KB Output is correct
7 Correct 23 ms 16224 KB Output is correct
8 Correct 16 ms 16256 KB Output is correct
9 Correct 20 ms 16256 KB Output is correct
10 Correct 22 ms 16384 KB Output is correct
11 Correct 18 ms 16256 KB Output is correct
12 Correct 20 ms 16256 KB Output is correct
13 Correct 20 ms 16256 KB Output is correct
14 Correct 23 ms 16264 KB Output is correct
15 Correct 22 ms 16248 KB Output is correct
16 Correct 21 ms 16256 KB Output is correct
17 Correct 20 ms 16256 KB Output is correct
18 Correct 21 ms 16256 KB Output is correct
19 Correct 36 ms 16892 KB Output is correct
20 Correct 35 ms 17016 KB Output is correct
21 Correct 36 ms 16896 KB Output is correct
22 Correct 36 ms 17016 KB Output is correct
23 Correct 37 ms 16896 KB Output is correct
24 Correct 44 ms 16896 KB Output is correct
25 Correct 44 ms 16956 KB Output is correct
26 Correct 35 ms 16896 KB Output is correct
27 Correct 40 ms 16888 KB Output is correct
28 Correct 34 ms 16896 KB Output is correct
29 Correct 29 ms 17140 KB Output is correct
30 Correct 110 ms 18672 KB Output is correct
31 Correct 181 ms 20588 KB Output is correct
32 Correct 179 ms 20728 KB Output is correct
33 Correct 171 ms 20452 KB Output is correct
34 Correct 179 ms 20592 KB Output is correct
35 Correct 158 ms 20556 KB Output is correct
36 Correct 142 ms 20588 KB Output is correct
37 Correct 169 ms 20664 KB Output is correct
38 Correct 170 ms 20220 KB Output is correct
39 Correct 123 ms 20092 KB Output is correct
40 Correct 133 ms 20080 KB Output is correct
41 Correct 123 ms 20332 KB Output is correct
42 Correct 131 ms 20204 KB Output is correct
43 Correct 118 ms 20204 KB Output is correct
44 Correct 119 ms 20100 KB Output is correct
45 Correct 125 ms 20204 KB Output is correct
46 Correct 113 ms 20076 KB Output is correct
47 Correct 675 ms 32544 KB Output is correct
48 Correct 2685 ms 63456 KB Output is correct
49 Correct 3087 ms 66648 KB Output is correct
50 Correct 3109 ms 66780 KB Output is correct
51 Correct 2792 ms 66568 KB Output is correct
52 Correct 2907 ms 66584 KB Output is correct
53 Correct 3372 ms 66564 KB Output is correct
54 Correct 2709 ms 66780 KB Output is correct
55 Correct 2951 ms 66828 KB Output is correct
56 Correct 2635 ms 66828 KB Output is correct
57 Correct 2779 ms 66844 KB Output is correct
58 Correct 2256 ms 66668 KB Output is correct
59 Correct 2273 ms 65508 KB Output is correct
60 Correct 2189 ms 65440 KB Output is correct
61 Correct 2446 ms 65364 KB Output is correct
62 Correct 2213 ms 65228 KB Output is correct
63 Correct 2257 ms 65444 KB Output is correct
64 Correct 2067 ms 65332 KB Output is correct
65 Correct 2059 ms 65136 KB Output is correct
66 Correct 1971 ms 65060 KB Output is correct
67 Correct 2157 ms 65080 KB Output is correct