Submission #97353

# Submission time Handle Problem Language Result Execution time Memory
97353 2019-02-15T12:46:14 Z diamond_duke Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
4041 ms 67896 KB
#include "bubblesort2.h"
#include <algorithm>
#include <utility>
using ll = long long;
namespace segT
{
	ll seg[4000005], lazy[4000005];
	inline void paint(int u, int x)
	{
		seg[u] += x;
		lazy[u] += x;
	}
	inline void push_down(int u)
	{
		if (lazy[u])
		{
			paint(u << 1, lazy[u]);
			paint(u << 1 | 1, lazy[u]);
			lazy[u] = 0;
		}
	}
	inline void modify(int u, int l, int r, int L, int R, int x)
	{
		if (L <= l && r <= R)
		{
			paint(u, x);
			return;
		}
		push_down(u);
		int m = l + r >> 1;
		if (L <= m)
			modify(u << 1, l, m, L, R, x);
		if (m < R)
			modify(u << 1 | 1, m + 1, r, L, R, x);
		seg[u] = std::max(seg[u << 1], seg[u << 1 | 1]);
	}
}
std::vector<int> countScans(std::vector<int> arr, std::vector<int> qx, std::vector<int> qy)
{
	int n = arr.size(), q = qx.size();
	std::vector<std::pair<int, int> > app;
	for (int i = 0; i < n; i++)
		app.emplace_back(arr[i], i);
	for (int i = 0; i < q; i++)
		app.emplace_back(qy[i], qx[i]);
	std::sort(app.begin(), app.end());
	app.erase(std::unique(app.begin(), app.end()), app.end());
	auto search = [&] (int pos, int val)
	{
		return std::lower_bound(app.begin(), app.end(), std::make_pair(pos, val)) - app.begin();
	};
	auto modify = [&] (int pos, int coef)
	{
		int idx = search(arr[pos], pos);
		segT::modify(1, 0, app.size() - 1, idx, idx, pos * coef);
		segT::modify(1, 0, app.size() - 1, search(arr[pos], -1), app.size() - 1, -coef);
	};
	for (int i = 0; i < n; i++)
		modify(i, 1);
	std::vector<int> ans(q);
	for (int i = 0; i < q; i++)
	{
		int p = qx[i];
		modify(p, -1);
		arr[p] = qy[i];
		modify(p, 1);
		ans[i] = segT::seg[1] + 1;
	}
	return ans;
}

Compilation message

bubblesort2.cpp: In function 'void segT::modify(int, int, int, int, int, int)':
bubblesort2.cpp:30:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 10 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 7 ms 612 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 8 ms 684 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 7 ms 552 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 10 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 7 ms 612 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 8 ms 684 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 7 ms 552 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 25 ms 1408 KB Output is correct
20 Correct 29 ms 1536 KB Output is correct
21 Correct 24 ms 1408 KB Output is correct
22 Correct 24 ms 1664 KB Output is correct
23 Correct 28 ms 1528 KB Output is correct
24 Correct 24 ms 1536 KB Output is correct
25 Correct 25 ms 1408 KB Output is correct
26 Correct 23 ms 1408 KB Output is correct
27 Correct 21 ms 1404 KB Output is correct
28 Correct 24 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2108 KB Output is correct
2 Correct 132 ms 4080 KB Output is correct
3 Correct 235 ms 7276 KB Output is correct
4 Correct 180 ms 7148 KB Output is correct
5 Correct 161 ms 7276 KB Output is correct
6 Correct 200 ms 7148 KB Output is correct
7 Correct 173 ms 7148 KB Output is correct
8 Correct 214 ms 7320 KB Output is correct
9 Correct 176 ms 7148 KB Output is correct
10 Correct 159 ms 5184 KB Output is correct
11 Correct 119 ms 5228 KB Output is correct
12 Correct 141 ms 5228 KB Output is correct
13 Correct 136 ms 5124 KB Output is correct
14 Correct 133 ms 5228 KB Output is correct
15 Correct 129 ms 5204 KB Output is correct
16 Correct 100 ms 5228 KB Output is correct
17 Correct 135 ms 5216 KB Output is correct
18 Correct 127 ms 5156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 10 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 7 ms 612 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 8 ms 684 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 7 ms 552 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 25 ms 1408 KB Output is correct
20 Correct 29 ms 1536 KB Output is correct
21 Correct 24 ms 1408 KB Output is correct
22 Correct 24 ms 1664 KB Output is correct
23 Correct 28 ms 1528 KB Output is correct
24 Correct 24 ms 1536 KB Output is correct
25 Correct 25 ms 1408 KB Output is correct
26 Correct 23 ms 1408 KB Output is correct
27 Correct 21 ms 1404 KB Output is correct
28 Correct 24 ms 1400 KB Output is correct
29 Correct 38 ms 2108 KB Output is correct
30 Correct 132 ms 4080 KB Output is correct
31 Correct 235 ms 7276 KB Output is correct
32 Correct 180 ms 7148 KB Output is correct
33 Correct 161 ms 7276 KB Output is correct
34 Correct 200 ms 7148 KB Output is correct
35 Correct 173 ms 7148 KB Output is correct
36 Correct 214 ms 7320 KB Output is correct
37 Correct 176 ms 7148 KB Output is correct
38 Correct 159 ms 5184 KB Output is correct
39 Correct 119 ms 5228 KB Output is correct
40 Correct 141 ms 5228 KB Output is correct
41 Correct 136 ms 5124 KB Output is correct
42 Correct 133 ms 5228 KB Output is correct
43 Correct 129 ms 5204 KB Output is correct
44 Correct 100 ms 5228 KB Output is correct
45 Correct 135 ms 5216 KB Output is correct
46 Correct 127 ms 5156 KB Output is correct
47 Correct 1053 ms 26896 KB Output is correct
48 Correct 3729 ms 65068 KB Output is correct
49 Correct 3805 ms 67804 KB Output is correct
50 Correct 3741 ms 67664 KB Output is correct
51 Correct 4041 ms 67768 KB Output is correct
52 Correct 3803 ms 67700 KB Output is correct
53 Correct 3287 ms 67668 KB Output is correct
54 Correct 3587 ms 67864 KB Output is correct
55 Correct 3941 ms 67820 KB Output is correct
56 Correct 3272 ms 67696 KB Output is correct
57 Correct 3419 ms 67896 KB Output is correct
58 Correct 3115 ms 67860 KB Output is correct
59 Correct 2963 ms 66532 KB Output is correct
60 Correct 2786 ms 66648 KB Output is correct
61 Correct 2835 ms 66524 KB Output is correct
62 Correct 2625 ms 66484 KB Output is correct
63 Correct 2618 ms 66404 KB Output is correct
64 Correct 2664 ms 66532 KB Output is correct
65 Correct 2600 ms 66248 KB Output is correct
66 Correct 2660 ms 66148 KB Output is correct
67 Correct 2631 ms 66208 KB Output is correct