#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma region dalykai
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
using pf32 = pair<float, float>;
using pf64 = pair<double, double>;
using pf80 = pair<long double, long double>;
using vf32 = vector<float>;
using vf64 = vector<double>;
using vf80 = vector<long double>;
using vpf32 = vector<pf32>;
using vpf64 = vector<pf64>;
using vpf80 = vector<pf80>;
using vvf32 = vector<vf32>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;
using vvpf32 = vector<vpf32>;
using vvpf64 = vector<vpf64>;
using vvpf80 = vector<vpf80>;
template <typename key, typename val>
using ord_map = tree<key, val, less<key>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename key>
using ord_set = tree<key, null_type, less<key>, rb_tree_tag,
tree_order_statistics_node_update>;
const int BUF_SZ = 1 << 15;
inline namespace fast_in
{
char buf[BUF_SZ];
int pos;
int len;
char next_char(FILE *f)
{
if (pos == len)
{
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, f);
if (!len)
{
return EOF;
}
}
return buf[pos++];
}
int read_int(FILE *f)
{
int x;
char ch;
int sgn = 1;
while (!isdigit(ch = next_char(f)))
{
if (ch == '-')
{
sgn *= -1;
}
}
x = ch - '0';
while (isdigit(ch = next_char(f)))
{
x = x * 10 + (ch - '0');
}
return x * sgn;
}
}
/**
* @brief gale programos flush_out kviest!!
*/
inline namespace fast_out
{
char buf[BUF_SZ];
int pos;
void flush_out(FILE *f)
{
fwrite(buf, 1, pos, f);
pos = 0;
}
void write_char(char c, FILE *f)
{
if (pos == BUF_SZ)
{
flush_out(f);
}
buf[pos++] = c;
}
void write_int(int x, FILE *f)
{
static char num_buf[100];
if (x < 0)
{
write_char('-', f);
x *= -1;
}
int len = 0;
for (; x >= 10; x /= 10)
{
num_buf[len++] = (char)('0' + (x % 10));
}
write_char((char)('0' + x), f);
while (len)
{
write_char(num_buf[--len], f);
}
write_char('\n', f);
}
}
#pragma endregion
struct node_t
{
int value;
node_t *left;
node_t *right;
p64 range;
node_t(int v, p64 r)
{
value = v;
range = r;
left = nullptr;
right = nullptr;
}
void expand()
{
if (range.second - range.first == 1)
{
return;
}
int64_t mid = (range.first + range.second) / 2;
if (!left)
{
left = new node_t(0, {range.first, mid});
}
if (!right)
{
right = new node_t(0, {mid, range.second});
}
}
void recalc()
{
expand();
value = max(left->value, right->value);
}
};
int intersect(p64 a, p64 b)
{
if (a.first >= b.second || a.second <= b.first)
{
return 0;
}
if (a.first >= b.first && a.second <= b.second)
{
return 1;
}
return 2;
}
void update(int value, p64 dest, node_t *node)
{
if (!node || !intersect(node->range, dest))
{
return;
}
p64 &range = node->range;
if (range == dest)
{
node->value = max(node->value, value);
return;
}
node->expand();
update(value, dest, node->left);
update(value, dest, node->right);
node->recalc();
}
int query(p64 dest, node_t *node)
{
if (!node)
{
return 0;
}
p64 &range = node->range;
int res = intersect(range, dest);
if (!res)
{
return 0;
}
if (res == 1)
{
return node->value;
}
node->expand();
int left = query(dest, node->left);
int right = query(dest, node->right);
return max(left, right);
}
int main()
{
#ifndef _AAAAAAAAA
ios_base::sync_with_stdio(false);
cin.tie(0);
#else
freopen("triusis.in", "r", stdin);
#ifndef __linux__
atexit([]()
{
freopen("con", "r", stdin);
system("pause"); });
#endif
#endif
int64_t n, m;
cin >> n >> m;
vi64 height(n);
for (auto &h : height)
{
cin >> h;
}
int64_t lower = -1e9;
int64_t upper = 1e9 + 1;
node_t *node = new node_t(0, {lower, upper});
if (height.front() <= m)
{
update(1, {height[0] - m, height[0] - m + 1}, node);
}
int64_t total = height.front() <= m;
for (int i = 1; i < n; i++)
{
int64_t pos = height[i] - m * (i + 1);
int64_t cur = query({pos, upper}, node);
if (cur == 0 && height[i] > m * (i + 1))
{
continue;
}
update(cur + 1, {pos, pos + 1}, node);
total = max(total, cur + 1);
}
cout << n - total << '\n';
return 0;
}
Compilation message
triusis.cpp:8: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
8 | #pragma region dalykai
|
triusis.cpp:151: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
151 | #pragma endregion
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
5 ms |
1052 KB |
Output is correct |
21 |
Correct |
6 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
8 ms |
5792 KB |
Output is correct |
24 |
Correct |
9 ms |
6484 KB |
Output is correct |
25 |
Correct |
5 ms |
2504 KB |
Output is correct |
26 |
Correct |
9 ms |
4596 KB |
Output is correct |
27 |
Correct |
3 ms |
368 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
2260 KB |
Output is correct |
30 |
Correct |
6 ms |
2516 KB |
Output is correct |
31 |
Correct |
4 ms |
596 KB |
Output is correct |
32 |
Correct |
8 ms |
5204 KB |
Output is correct |
33 |
Correct |
9 ms |
5140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
5 ms |
1052 KB |
Output is correct |
5 |
Correct |
6 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
8 ms |
5792 KB |
Output is correct |
8 |
Correct |
9 ms |
6484 KB |
Output is correct |
9 |
Correct |
5 ms |
2504 KB |
Output is correct |
10 |
Correct |
9 ms |
4596 KB |
Output is correct |
11 |
Correct |
3 ms |
368 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
6 ms |
2516 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
8 ms |
5204 KB |
Output is correct |
17 |
Correct |
9 ms |
5140 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
9 ms |
8148 KB |
Output is correct |
35 |
Correct |
9 ms |
8156 KB |
Output is correct |
36 |
Correct |
9 ms |
8148 KB |
Output is correct |
37 |
Correct |
8 ms |
4600 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
3 ms |
340 KB |
Output is correct |
40 |
Correct |
3 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
9 ms |
5972 KB |
Output is correct |
43 |
Correct |
9 ms |
5884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
9 ms |
8156 KB |
Output is correct |
3 |
Correct |
9 ms |
8148 KB |
Output is correct |
4 |
Correct |
8 ms |
4600 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
5972 KB |
Output is correct |
10 |
Correct |
9 ms |
5884 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
1052 KB |
Output is correct |
15 |
Correct |
6 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
8 ms |
5792 KB |
Output is correct |
18 |
Correct |
9 ms |
6484 KB |
Output is correct |
19 |
Correct |
5 ms |
2504 KB |
Output is correct |
20 |
Correct |
9 ms |
4596 KB |
Output is correct |
21 |
Correct |
3 ms |
368 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
2260 KB |
Output is correct |
24 |
Correct |
6 ms |
2516 KB |
Output is correct |
25 |
Correct |
4 ms |
596 KB |
Output is correct |
26 |
Correct |
8 ms |
5204 KB |
Output is correct |
27 |
Correct |
9 ms |
5140 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
199 ms |
82096 KB |
Output is correct |
45 |
Correct |
360 ms |
218580 KB |
Output is correct |
46 |
Correct |
426 ms |
241232 KB |
Output is correct |
47 |
Correct |
433 ms |
241612 KB |
Output is correct |
48 |
Correct |
214 ms |
89148 KB |
Output is correct |
49 |
Correct |
284 ms |
173260 KB |
Output is correct |
50 |
Correct |
88 ms |
3808 KB |
Output is correct |
51 |
Correct |
78 ms |
3780 KB |
Output is correct |
52 |
Correct |
126 ms |
12060 KB |
Output is correct |
53 |
Correct |
58 ms |
3156 KB |
Output is correct |
54 |
Correct |
316 ms |
212396 KB |
Output is correct |
55 |
Correct |
317 ms |
211528 KB |
Output is correct |