# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95842 | 2019-02-03T03:18:20 Z | diamond_duke | Sparklers (JOI17_sparklers) | C++11 | 400 ms | 16892 KB |
#include <functional> #include <cstdio> using ll = long long; struct ST_table { std::function<int (int, int)> comp; int emp, lg[100005], arr[25][100005]; template <typename T> ST_table(int n, int _emp, T _comp) : comp(_comp), emp(_emp) { lg[0] = lg[1] = 0; for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1; for (int i = 0; i < n; i++) arr[0][i] = i; for (int i = 1; i <= lg[n]; i++) { for (int j = 0; j + (1 << i) <= n; j++) arr[i][j] = comp(arr[i - 1][j], arr[i - 1][j + (1 << i - 1)]); } } inline int operator ()(int l, int r) { if (l > r) return emp; int len = lg[r - l + 1]; return comp(arr[len][l], arr[len][r - (1 << len) + 1]); } }; ll val[100005]; int arr[100005], st[100005], pre[100005], nxt[100005]; inline bool check(int n, int stp, ll lim) { for (int i = 0; i < n; i++) val[i] = arr[i] - lim * i; val[n] = 1e18; val[n + 1] = -1e18; ST_table qmin(n, n, [&] (int x, int y) { return val[x] < val[y] ? x : y; }); ST_table qmax(n, n + 1, [&] (int x, int y) { return val[x] > val[y] ? x : y; }); int tp = 0; st[tp] = -1; for (int i = 0; i < n; i++) { while (tp && val[st[tp]] <= val[i]) tp--; pre[i] = st[tp]; st[++tp] = i; } tp = 0; st[tp] = n; for (int i = n - 1; i >= 0; i--) { while (tp && val[st[tp]] >= val[i]) tp--; nxt[i] = st[tp]; st[++tp] = i; } int l = stp, r = stp; while (l || r != n - 1) { int x = pre[l], y = nxt[r]; if (~x && val[qmin(x + 1, l - 1)] >= val[r]) l = x; else if (y != n && val[qmax(r + 1, y - 1)] <= val[l]) r = y; else { if (!l) return val[qmax(r + 1, n - 1)] <= val[l]; if (r == n - 1) return val[qmin(0, l - 1)] >= val[r]; x = qmin(0, l - 1); y = qmax(r + 1, n - 1); if (val[x] < val[r] || val[y] > val[l]) return false; int a = qmax(0, x), b = qmin(y, n - 1); if (val[a] >= val[y]) l = a; else if (val[b] <= val[x]) r = b; else return false; } } return true; } int main() { // freopen("loj-2392.in", "r", stdin); int n, stp, T; scanf("%d%d%d", &n, &stp, &T); for (int i = 0; i < n; i++) scanf("%d", arr + i); int l = 0, r = (arr[n - 1] - arr[0]) / T / 2 + 1, res = -1; while (l <= r) { int m = l + r >> 1; if (check(n, stp - 1, (ll)2 * m * T)) { res = m; r = m - 1; } else l = m + 1; } printf("%d\n", res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 392 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 404 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 396 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 392 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 404 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 396 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 3 ms | 504 KB | Output is correct |
23 | Correct | 3 ms | 508 KB | Output is correct |
24 | Correct | 3 ms | 504 KB | Output is correct |
25 | Correct | 4 ms | 632 KB | Output is correct |
26 | Correct | 3 ms | 632 KB | Output is correct |
27 | Correct | 4 ms | 504 KB | Output is correct |
28 | Correct | 4 ms | 632 KB | Output is correct |
29 | Correct | 4 ms | 504 KB | Output is correct |
30 | Correct | 4 ms | 504 KB | Output is correct |
31 | Correct | 4 ms | 504 KB | Output is correct |
32 | Correct | 4 ms | 652 KB | Output is correct |
33 | Correct | 4 ms | 504 KB | Output is correct |
34 | Correct | 4 ms | 504 KB | Output is correct |
35 | Correct | 4 ms | 504 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 4 ms | 508 KB | Output is correct |
39 | Correct | 4 ms | 504 KB | Output is correct |
40 | Correct | 2 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 392 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 404 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 396 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 3 ms | 504 KB | Output is correct |
23 | Correct | 3 ms | 508 KB | Output is correct |
24 | Correct | 3 ms | 504 KB | Output is correct |
25 | Correct | 4 ms | 632 KB | Output is correct |
26 | Correct | 3 ms | 632 KB | Output is correct |
27 | Correct | 4 ms | 504 KB | Output is correct |
28 | Correct | 4 ms | 632 KB | Output is correct |
29 | Correct | 4 ms | 504 KB | Output is correct |
30 | Correct | 4 ms | 504 KB | Output is correct |
31 | Correct | 4 ms | 504 KB | Output is correct |
32 | Correct | 4 ms | 652 KB | Output is correct |
33 | Correct | 4 ms | 504 KB | Output is correct |
34 | Correct | 4 ms | 504 KB | Output is correct |
35 | Correct | 4 ms | 504 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 4 ms | 508 KB | Output is correct |
39 | Correct | 4 ms | 504 KB | Output is correct |
40 | Correct | 2 ms | 504 KB | Output is correct |
41 | Correct | 182 ms | 11000 KB | Output is correct |
42 | Correct | 7 ms | 760 KB | Output is correct |
43 | Correct | 46 ms | 3192 KB | Output is correct |
44 | Correct | 351 ms | 16816 KB | Output is correct |
45 | Correct | 352 ms | 16760 KB | Output is correct |
46 | Correct | 342 ms | 16892 KB | Output is correct |
47 | Correct | 338 ms | 16888 KB | Output is correct |
48 | Correct | 351 ms | 16888 KB | Output is correct |
49 | Correct | 336 ms | 16888 KB | Output is correct |
50 | Correct | 356 ms | 16800 KB | Output is correct |
51 | Correct | 348 ms | 16812 KB | Output is correct |
52 | Correct | 400 ms | 16812 KB | Output is correct |
53 | Correct | 338 ms | 16888 KB | Output is correct |
54 | Correct | 340 ms | 16760 KB | Output is correct |
55 | Correct | 357 ms | 16888 KB | Output is correct |
56 | Correct | 328 ms | 16760 KB | Output is correct |
57 | Correct | 380 ms | 16888 KB | Output is correct |
58 | Correct | 339 ms | 16860 KB | Output is correct |
59 | Correct | 31 ms | 15608 KB | Output is correct |
60 | Correct | 322 ms | 16760 KB | Output is correct |
61 | Correct | 296 ms | 16760 KB | Output is correct |
62 | Correct | 320 ms | 16808 KB | Output is correct |
63 | Correct | 323 ms | 16888 KB | Output is correct |
64 | Correct | 323 ms | 16760 KB | Output is correct |
65 | Correct | 342 ms | 16808 KB | Output is correct |
66 | Correct | 312 ms | 16784 KB | Output is correct |
67 | Correct | 312 ms | 16752 KB | Output is correct |
68 | Correct | 322 ms | 16808 KB | Output is correct |
69 | Correct | 297 ms | 16760 KB | Output is correct |