Submission #67499

# Submission time Handle Problem Language Result Execution time Memory
67499 2018-08-14T11:16:10 Z aome Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
2902 ms 77016 KB
#include "bubblesort2.h"

#include <bits/stdc++.h>

using namespace std;

const int N = 500005;
const int INF = 0x3f3f3f;

struct SegmentTree {
	int Tmax[N << 3];
	int Tcnt[N << 3];
	int lazy[N << 3];

	SegmentTree() {
		memset(Tmax, -INF, sizeof Tmax);
	}

	void push(int i, int l, int r) {
		Tmax[i] += lazy[i];
		if (l != r) {
			lazy[i << 1] += lazy[i], lazy[i << 1 | 1] += lazy[i];
		}
		lazy[i] = 0;
	}

	#define mid ((l + r) >> 1)

	void updRange(int i, int l, int r, int L, int R, int x) {
		push(i, l, r);
		if (l > R || L > r) return;
		if (L <= l && r <= R) {
			lazy[i] = x, push(i, l, r); return;
		}
		updRange(i << 1, l, mid, L, R, x);
		updRange(i << 1 | 1, mid + 1, r, L, R, x);
		Tmax[i] = max(Tmax[i << 1], Tmax[i << 1 | 1]);
	}

	void updPos(int i, int l, int r, int p, int x, int y) {
		push(i, l, r);
		if (p > r || l > p) return;
		if (l == r) { Tmax[i] = x, Tcnt[i] = y; return; }
		updPos(i << 1, l, mid, p, x, y);
		updPos(i << 1 | 1, mid + 1, r, p, x, y);
		Tcnt[i] = Tcnt[i << 1] + Tcnt[i << 1 | 1];
		Tmax[i] = max(Tmax[i << 1], Tmax[i << 1 | 1]);
	}

	int get(int i, int l, int r, int L, int R) {
		if (l > R || L > r) return 0;
		if (L <= l && r <= R) return Tcnt[i];
		return get(i << 1, l, mid, L, R) + get(i << 1 | 1, mid + 1, r, L, R);
	}

	#undef mid
} IT;

struct Data {
	int v, p, id;

	bool operator < (const Data& rhs) const {
		return v == rhs.v ? p < rhs.p : v < rhs.v;
	}
};	

int prv[N], pos[N];
vector<Data> vec;

vector<int> countScans(vector<int> a, vector<int> x, vector<int> y) {
	int n = a.size(), m = x.size();
	for (int i = 0; i < n; ++i) vec.push_back({a[i], i, i});
	for (int i = 0; i < m; ++i) vec.push_back({y[i], x[i], i + n});
	sort(vec.begin(), vec.end());
	int sz = n + m;
	for (int i = 0; i < sz; ++i) {
		if (vec[i].id >= n) {
			pos[vec[i].id - n] = i; continue;
		}
		int F = vec[i].p - IT.get(1, 0, sz - 1, 0, i);
		IT.updPos(1, 0, sz - 1, i, F, 1), prv[vec[i].p] = i;
	}
	vector<int> res;
	for (int i = 0; i < m; ++i) {
		int &tmp = prv[x[i]];
		IT.updRange(1, 0, sz - 1, tmp, sz - 1, 1);
		IT.updPos(1, 0, sz - 1, tmp, -INF, 0);
		tmp = pos[i];
		int F = x[i] - IT.get(1, 0, sz - 1, 0, tmp);
		IT.updRange(1, 0, sz - 1, tmp, sz - 1, -1);
		IT.updPos(1, 0, sz - 1, tmp, F, 1);
		res.push_back(IT.Tmax[1]);
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16120 KB Output is correct
2 Correct 16 ms 16324 KB Output is correct
3 Correct 19 ms 16460 KB Output is correct
4 Correct 20 ms 16528 KB Output is correct
5 Correct 22 ms 16528 KB Output is correct
6 Correct 18 ms 16556 KB Output is correct
7 Correct 19 ms 16628 KB Output is correct
8 Correct 19 ms 16932 KB Output is correct
9 Correct 19 ms 16932 KB Output is correct
10 Correct 19 ms 16932 KB Output is correct
11 Correct 20 ms 16932 KB Output is correct
12 Correct 19 ms 17008 KB Output is correct
13 Correct 19 ms 17048 KB Output is correct
14 Correct 19 ms 17156 KB Output is correct
15 Correct 19 ms 17156 KB Output is correct
16 Correct 22 ms 17156 KB Output is correct
17 Correct 18 ms 17164 KB Output is correct
18 Correct 21 ms 17332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16120 KB Output is correct
2 Correct 16 ms 16324 KB Output is correct
3 Correct 19 ms 16460 KB Output is correct
4 Correct 20 ms 16528 KB Output is correct
5 Correct 22 ms 16528 KB Output is correct
6 Correct 18 ms 16556 KB Output is correct
7 Correct 19 ms 16628 KB Output is correct
8 Correct 19 ms 16932 KB Output is correct
9 Correct 19 ms 16932 KB Output is correct
10 Correct 19 ms 16932 KB Output is correct
11 Correct 20 ms 16932 KB Output is correct
12 Correct 19 ms 17008 KB Output is correct
13 Correct 19 ms 17048 KB Output is correct
14 Correct 19 ms 17156 KB Output is correct
15 Correct 19 ms 17156 KB Output is correct
16 Correct 22 ms 17156 KB Output is correct
17 Correct 18 ms 17164 KB Output is correct
18 Correct 21 ms 17332 KB Output is correct
19 Correct 37 ms 18008 KB Output is correct
20 Correct 36 ms 18228 KB Output is correct
21 Correct 34 ms 18416 KB Output is correct
22 Correct 44 ms 18692 KB Output is correct
23 Correct 45 ms 18856 KB Output is correct
24 Correct 36 ms 18924 KB Output is correct
25 Correct 34 ms 19088 KB Output is correct
26 Correct 41 ms 19248 KB Output is correct
27 Correct 34 ms 19408 KB Output is correct
28 Correct 35 ms 19576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 20292 KB Output is correct
2 Correct 88 ms 22168 KB Output is correct
3 Correct 186 ms 25168 KB Output is correct
4 Correct 166 ms 25168 KB Output is correct
5 Correct 195 ms 25168 KB Output is correct
6 Correct 165 ms 25168 KB Output is correct
7 Correct 190 ms 25168 KB Output is correct
8 Correct 166 ms 25272 KB Output is correct
9 Correct 172 ms 26068 KB Output is correct
10 Correct 210 ms 26556 KB Output is correct
11 Correct 157 ms 26556 KB Output is correct
12 Correct 202 ms 26584 KB Output is correct
13 Correct 171 ms 26584 KB Output is correct
14 Correct 165 ms 26736 KB Output is correct
15 Correct 197 ms 26736 KB Output is correct
16 Correct 148 ms 26736 KB Output is correct
17 Correct 154 ms 26736 KB Output is correct
18 Correct 154 ms 26736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16120 KB Output is correct
2 Correct 16 ms 16324 KB Output is correct
3 Correct 19 ms 16460 KB Output is correct
4 Correct 20 ms 16528 KB Output is correct
5 Correct 22 ms 16528 KB Output is correct
6 Correct 18 ms 16556 KB Output is correct
7 Correct 19 ms 16628 KB Output is correct
8 Correct 19 ms 16932 KB Output is correct
9 Correct 19 ms 16932 KB Output is correct
10 Correct 19 ms 16932 KB Output is correct
11 Correct 20 ms 16932 KB Output is correct
12 Correct 19 ms 17008 KB Output is correct
13 Correct 19 ms 17048 KB Output is correct
14 Correct 19 ms 17156 KB Output is correct
15 Correct 19 ms 17156 KB Output is correct
16 Correct 22 ms 17156 KB Output is correct
17 Correct 18 ms 17164 KB Output is correct
18 Correct 21 ms 17332 KB Output is correct
19 Correct 37 ms 18008 KB Output is correct
20 Correct 36 ms 18228 KB Output is correct
21 Correct 34 ms 18416 KB Output is correct
22 Correct 44 ms 18692 KB Output is correct
23 Correct 45 ms 18856 KB Output is correct
24 Correct 36 ms 18924 KB Output is correct
25 Correct 34 ms 19088 KB Output is correct
26 Correct 41 ms 19248 KB Output is correct
27 Correct 34 ms 19408 KB Output is correct
28 Correct 35 ms 19576 KB Output is correct
29 Correct 39 ms 20292 KB Output is correct
30 Correct 88 ms 22168 KB Output is correct
31 Correct 186 ms 25168 KB Output is correct
32 Correct 166 ms 25168 KB Output is correct
33 Correct 195 ms 25168 KB Output is correct
34 Correct 165 ms 25168 KB Output is correct
35 Correct 190 ms 25168 KB Output is correct
36 Correct 166 ms 25272 KB Output is correct
37 Correct 172 ms 26068 KB Output is correct
38 Correct 210 ms 26556 KB Output is correct
39 Correct 157 ms 26556 KB Output is correct
40 Correct 202 ms 26584 KB Output is correct
41 Correct 171 ms 26584 KB Output is correct
42 Correct 165 ms 26736 KB Output is correct
43 Correct 197 ms 26736 KB Output is correct
44 Correct 148 ms 26736 KB Output is correct
45 Correct 154 ms 26736 KB Output is correct
46 Correct 154 ms 26736 KB Output is correct
47 Correct 634 ms 39220 KB Output is correct
48 Correct 2395 ms 69372 KB Output is correct
49 Correct 2902 ms 71528 KB Output is correct
50 Correct 2709 ms 74324 KB Output is correct
51 Correct 2309 ms 74324 KB Output is correct
52 Correct 2519 ms 74324 KB Output is correct
53 Correct 2440 ms 74324 KB Output is correct
54 Correct 2564 ms 74324 KB Output is correct
55 Correct 2555 ms 74324 KB Output is correct
56 Correct 2568 ms 74324 KB Output is correct
57 Correct 2697 ms 74324 KB Output is correct
58 Correct 2601 ms 74324 KB Output is correct
59 Correct 2336 ms 74324 KB Output is correct
60 Correct 2252 ms 74372 KB Output is correct
61 Correct 2048 ms 74372 KB Output is correct
62 Correct 2500 ms 74836 KB Output is correct
63 Correct 2125 ms 74900 KB Output is correct
64 Correct 2282 ms 74900 KB Output is correct
65 Correct 1997 ms 74900 KB Output is correct
66 Correct 2354 ms 76944 KB Output is correct
67 Correct 2213 ms 77016 KB Output is correct