Submission #95999

# Submission time Handle Problem Language Result Execution time Memory
95999 2019-02-05T04:27:12 Z diamond_duke Bubble Sort 2 (JOI18_bubblesort2) C++11
60 / 100
557 ms 50136 KB
#include "bubblesort2.h"
#include <algorithm>
#include <utility>
#include <vector>
using ll = long long;
ll seg[2000005], lazy[2000005];
inline void paint(int u, ll 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, ll 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> qv)
{
	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(qv[i], qx[i]);
	std::sort(app.begin(), app.end());
	app.erase(std::unique(app.begin(), app.end()), app.end());
	auto get_idx = [&] (std::pair<int, int> x)
	{
		return std::lower_bound(app.begin(), app.end(), x) - app.begin();
	};
	auto update = [&] (int pos, int coef)
	{
		int idx = get_idx({arr[pos], pos});
		modify(1, 0, app.size() - 1, idx, idx, pos * coef);
		modify(1, 0, app.size() - 1, get_idx({arr[pos], -1}), app.size() - 1, -coef);
	};
	for (int i = 0; i < n; i++)
		update(i, 1);
	std::vector<int> ans(q);
	for (int i = 0; i < q; i++)
	{
		int x = qx[i];
		update(x, -1);
		arr[x] = qv[i];
		update(x, 1);
		ans[i] = seg[1] + 1;
	}
	return ans;
}

Compilation message

bubblesort2.cpp: In function 'void modify(int, int, int, int, int, ll)':
bubblesort2.cpp:29:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1;
          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 18 ms 1400 KB Output is correct
20 Correct 20 ms 1528 KB Output is correct
21 Correct 19 ms 1400 KB Output is correct
22 Correct 20 ms 1400 KB Output is correct
23 Correct 19 ms 1400 KB Output is correct
24 Correct 19 ms 1400 KB Output is correct
25 Correct 18 ms 1400 KB Output is correct
26 Correct 18 ms 1400 KB Output is correct
27 Correct 18 ms 1400 KB Output is correct
28 Correct 17 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2040 KB Output is correct
2 Correct 76 ms 4108 KB Output is correct
3 Correct 152 ms 7132 KB Output is correct
4 Correct 153 ms 7148 KB Output is correct
5 Correct 153 ms 7148 KB Output is correct
6 Correct 140 ms 7148 KB Output is correct
7 Correct 142 ms 7276 KB Output is correct
8 Correct 144 ms 7148 KB Output is correct
9 Correct 137 ms 7148 KB Output is correct
10 Correct 99 ms 5228 KB Output is correct
11 Correct 96 ms 5200 KB Output is correct
12 Correct 97 ms 5228 KB Output is correct
13 Correct 95 ms 5228 KB Output is correct
14 Correct 93 ms 5168 KB Output is correct
15 Correct 95 ms 5228 KB Output is correct
16 Correct 88 ms 5176 KB Output is correct
17 Correct 91 ms 5248 KB Output is correct
18 Correct 92 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 18 ms 1400 KB Output is correct
20 Correct 20 ms 1528 KB Output is correct
21 Correct 19 ms 1400 KB Output is correct
22 Correct 20 ms 1400 KB Output is correct
23 Correct 19 ms 1400 KB Output is correct
24 Correct 19 ms 1400 KB Output is correct
25 Correct 18 ms 1400 KB Output is correct
26 Correct 18 ms 1400 KB Output is correct
27 Correct 18 ms 1400 KB Output is correct
28 Correct 17 ms 1400 KB Output is correct
29 Correct 25 ms 2040 KB Output is correct
30 Correct 76 ms 4108 KB Output is correct
31 Correct 152 ms 7132 KB Output is correct
32 Correct 153 ms 7148 KB Output is correct
33 Correct 153 ms 7148 KB Output is correct
34 Correct 140 ms 7148 KB Output is correct
35 Correct 142 ms 7276 KB Output is correct
36 Correct 144 ms 7148 KB Output is correct
37 Correct 137 ms 7148 KB Output is correct
38 Correct 99 ms 5228 KB Output is correct
39 Correct 96 ms 5200 KB Output is correct
40 Correct 97 ms 5228 KB Output is correct
41 Correct 95 ms 5228 KB Output is correct
42 Correct 93 ms 5168 KB Output is correct
43 Correct 95 ms 5228 KB Output is correct
44 Correct 88 ms 5176 KB Output is correct
45 Correct 91 ms 5248 KB Output is correct
46 Correct 92 ms 5228 KB Output is correct
47 Correct 557 ms 26812 KB Output is correct
48 Runtime error 319 ms 50136 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Halted 0 ms 0 KB -