// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "queue"
#include "towers.h"
#define all(x) x.begin(), x.end()
using namespace std;
vector<int> h;
int dd;
struct node {
int lval;
int rval;
int cnt;
int lstenka;
int rstenka;
node() {}
node(int x) {
lval = rval = x;
cnt = 1;
lstenka = 0;
rstenka = 0;
}
void swapchik() {
swap(lval, rval);
swap(lstenka, rstenka);
}
};
node merge(node a, node b) {
bool swp = 0;
if (a.rval > b.lval) {
swp = 1;
a.swapchik();
b.swapchik();
swap(a, b);
}
node c = a;
if (max(a.rstenka, b.lstenka) - dd >= max(a.rval, b.lval)) {
c.cnt = a.cnt + b.cnt;
c.rstenka = b.rstenka;
c.rval = b.rval;
if (swp)
c.swapchik();
return c;
} else {
c.cnt = a.cnt + b.cnt - 1;
if (b.cnt != 1) {
c.rstenka = b.rstenka;
c.rval = b.rval;
} else {
// cout << c.rstenka << ' ';
c.rstenka = max(c.rstenka, max(b.rstenka, max(b.lstenka, b.rval)));
// cout << c.rstenka << '\n';
}
if (swp)
c.swapchik();
return c;
}
}
struct kornihunka{
vector<int> elems;
node nd;
void push(int x) {
elems.push_back(x);
}
node get(int l, int r) {
r = min(r, (int)elems.size() - 1);
node nres(elems[l]);
for (int i = l + 1; i <= r; ++i) {
nres = merge(nres, node(elems[i]));
}
return nres;
}
void calc() {
nd = node(elems[0]);
for (int i = 1; i < elems.size(); ++i) {
nd = merge(nd, elems[i]);
}
}
node getnode() {
return nd;
}
};
int K = 337;
vector<kornihunka> vecnode;
int calcedd = 0;
void init(int n, vector<int> hh) {
h = hh;
vecnode.assign((n + K - 1) / K, {});
for (int i = 0; i < n; ++i) {
vecnode[i/K].push(h[i]);
}
}
int max_towers(int L, int R, int D) {
node res(2e9);
if (calcedd != D) {
if (calcedd != 0)
exit(1);
calcedd = D;
dd = D;
for (int i = 0; i < vecnode.size(); ++i) {
vecnode[i].calc();
}
}
if (L / K == R / K) {
// cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
res = merge(res, vecnode[L/K].get(L % K, R % K));
return res.cnt;
}
if (L % K != 0) {
// cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
res = merge(res, vecnode[L/K].get(L % K, K - 1));
L = L / K * K + K;
}
while (L + K <= R + 1) {
//cout << "TT " << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
node res2 = vecnode[L/K].getnode();
//cout << "TT2 " << res2.lval << ' ' << res2.lstenka << ' ' << res2.cnt << '\n';
res = merge(res, vecnode[L/K].getnode());
//cout << "TT3 " << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
L += K;
}
if (L <= R) {
// cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
res = merge(res, vecnode[L/K].get(L % K, R % K));
}
// cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
return res.cnt;
}
/*
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
init(n, a);
for (int i = 0; i < m; ++i) {
int q1, q2, q3;
cin >> q1 >> q2 >> q3;
cout << max_towers(q1,q2,q3) << '\n';
}
}*/
/*
7 1
10 20 60 40 50 30 70
0 6 17
*/
Compilation message
towers.cpp: In member function 'void kornihunka::calc()':
towers.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = 1; i < elems.size(); ++i) {
| ~~^~~~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:114:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<kornihunka>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for (int i = 0; i < vecnode.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~
towers.cpp:130:14: warning: variable 'res2' set but not used [-Wunused-but-set-variable]
130 | node res2 = vecnode[L/K].getnode();
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1352 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
11 ms |
1460 KB |
Output is correct |
37 |
Correct |
19 ms |
2064 KB |
Output is correct |
38 |
Correct |
16 ms |
2076 KB |
Output is correct |
39 |
Correct |
14 ms |
1964 KB |
Output is correct |
40 |
Correct |
16 ms |
2080 KB |
Output is correct |
41 |
Correct |
15 ms |
2076 KB |
Output is correct |
42 |
Correct |
15 ms |
2060 KB |
Output is correct |
43 |
Correct |
15 ms |
2052 KB |
Output is correct |
44 |
Correct |
15 ms |
2000 KB |
Output is correct |
45 |
Correct |
14 ms |
1956 KB |
Output is correct |
46 |
Correct |
17 ms |
2064 KB |
Output is correct |
47 |
Correct |
15 ms |
2044 KB |
Output is correct |
48 |
Correct |
15 ms |
1952 KB |
Output is correct |
49 |
Correct |
16 ms |
2080 KB |
Output is correct |
50 |
Correct |
15 ms |
2000 KB |
Output is correct |
51 |
Correct |
22 ms |
1956 KB |
Output is correct |
52 |
Correct |
21 ms |
2072 KB |
Output is correct |
53 |
Correct |
16 ms |
1992 KB |
Output is correct |
54 |
Correct |
18 ms |
2076 KB |
Output is correct |
55 |
Correct |
17 ms |
1976 KB |
Output is correct |
56 |
Correct |
23 ms |
1992 KB |
Output is correct |
57 |
Correct |
15 ms |
2000 KB |
Output is correct |
58 |
Correct |
14 ms |
1996 KB |
Output is correct |
59 |
Correct |
15 ms |
2060 KB |
Output is correct |
60 |
Correct |
24 ms |
1960 KB |
Output is correct |
61 |
Correct |
17 ms |
1956 KB |
Output is correct |
62 |
Correct |
18 ms |
2076 KB |
Output is correct |
63 |
Correct |
15 ms |
2072 KB |
Output is correct |
64 |
Correct |
15 ms |
1968 KB |
Output is correct |
65 |
Correct |
15 ms |
2000 KB |
Output is correct |
66 |
Correct |
15 ms |
1992 KB |
Output is correct |
67 |
Correct |
16 ms |
2084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1275 ms |
1952 KB |
Output is correct |
2 |
Correct |
2058 ms |
1948 KB |
Output is correct |
3 |
Correct |
1846 ms |
2076 KB |
Output is correct |
4 |
Correct |
1906 ms |
2076 KB |
Output is correct |
5 |
Correct |
1662 ms |
2076 KB |
Output is correct |
6 |
Correct |
1856 ms |
1956 KB |
Output is correct |
7 |
Correct |
1738 ms |
2068 KB |
Output is correct |
8 |
Correct |
1693 ms |
2076 KB |
Output is correct |
9 |
Correct |
1703 ms |
2080 KB |
Output is correct |
10 |
Correct |
1829 ms |
1992 KB |
Output is correct |
11 |
Correct |
1923 ms |
2120 KB |
Output is correct |
12 |
Correct |
1736 ms |
2064 KB |
Output is correct |
13 |
Correct |
1831 ms |
1948 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
17 ms |
2064 KB |
Output is correct |
18 |
Correct |
15 ms |
2072 KB |
Output is correct |
19 |
Correct |
15 ms |
1956 KB |
Output is correct |
20 |
Correct |
15 ms |
2064 KB |
Output is correct |
21 |
Correct |
16 ms |
2076 KB |
Output is correct |
22 |
Correct |
17 ms |
2076 KB |
Output is correct |
23 |
Correct |
15 ms |
2068 KB |
Output is correct |
24 |
Correct |
17 ms |
1960 KB |
Output is correct |
25 |
Correct |
15 ms |
2064 KB |
Output is correct |
26 |
Correct |
17 ms |
1956 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
672 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
11 ms |
1460 KB |
Output is correct |
37 |
Correct |
19 ms |
2064 KB |
Output is correct |
38 |
Correct |
16 ms |
2076 KB |
Output is correct |
39 |
Correct |
14 ms |
1964 KB |
Output is correct |
40 |
Correct |
16 ms |
2080 KB |
Output is correct |
41 |
Correct |
15 ms |
2076 KB |
Output is correct |
42 |
Correct |
15 ms |
2060 KB |
Output is correct |
43 |
Correct |
15 ms |
2052 KB |
Output is correct |
44 |
Correct |
15 ms |
2000 KB |
Output is correct |
45 |
Correct |
14 ms |
1956 KB |
Output is correct |
46 |
Correct |
17 ms |
2064 KB |
Output is correct |
47 |
Correct |
15 ms |
2044 KB |
Output is correct |
48 |
Correct |
15 ms |
1952 KB |
Output is correct |
49 |
Correct |
16 ms |
2080 KB |
Output is correct |
50 |
Correct |
15 ms |
2000 KB |
Output is correct |
51 |
Correct |
22 ms |
1956 KB |
Output is correct |
52 |
Correct |
21 ms |
2072 KB |
Output is correct |
53 |
Correct |
16 ms |
1992 KB |
Output is correct |
54 |
Correct |
18 ms |
2076 KB |
Output is correct |
55 |
Correct |
17 ms |
1976 KB |
Output is correct |
56 |
Correct |
23 ms |
1992 KB |
Output is correct |
57 |
Correct |
15 ms |
2000 KB |
Output is correct |
58 |
Correct |
14 ms |
1996 KB |
Output is correct |
59 |
Correct |
15 ms |
2060 KB |
Output is correct |
60 |
Correct |
24 ms |
1960 KB |
Output is correct |
61 |
Correct |
17 ms |
1956 KB |
Output is correct |
62 |
Correct |
18 ms |
2076 KB |
Output is correct |
63 |
Correct |
15 ms |
2072 KB |
Output is correct |
64 |
Correct |
15 ms |
1968 KB |
Output is correct |
65 |
Correct |
15 ms |
2000 KB |
Output is correct |
66 |
Correct |
15 ms |
1992 KB |
Output is correct |
67 |
Correct |
16 ms |
2084 KB |
Output is correct |
68 |
Correct |
1275 ms |
1952 KB |
Output is correct |
69 |
Correct |
2058 ms |
1948 KB |
Output is correct |
70 |
Correct |
1846 ms |
2076 KB |
Output is correct |
71 |
Correct |
1906 ms |
2076 KB |
Output is correct |
72 |
Correct |
1662 ms |
2076 KB |
Output is correct |
73 |
Correct |
1856 ms |
1956 KB |
Output is correct |
74 |
Correct |
1738 ms |
2068 KB |
Output is correct |
75 |
Correct |
1693 ms |
2076 KB |
Output is correct |
76 |
Correct |
1703 ms |
2080 KB |
Output is correct |
77 |
Correct |
1829 ms |
1992 KB |
Output is correct |
78 |
Correct |
1923 ms |
2120 KB |
Output is correct |
79 |
Correct |
1736 ms |
2064 KB |
Output is correct |
80 |
Correct |
1831 ms |
1948 KB |
Output is correct |
81 |
Correct |
0 ms |
208 KB |
Output is correct |
82 |
Correct |
1 ms |
208 KB |
Output is correct |
83 |
Correct |
1 ms |
208 KB |
Output is correct |
84 |
Correct |
17 ms |
2064 KB |
Output is correct |
85 |
Correct |
15 ms |
2072 KB |
Output is correct |
86 |
Correct |
15 ms |
1956 KB |
Output is correct |
87 |
Correct |
15 ms |
2064 KB |
Output is correct |
88 |
Correct |
16 ms |
2076 KB |
Output is correct |
89 |
Correct |
17 ms |
2076 KB |
Output is correct |
90 |
Correct |
15 ms |
2068 KB |
Output is correct |
91 |
Correct |
17 ms |
1960 KB |
Output is correct |
92 |
Correct |
15 ms |
2064 KB |
Output is correct |
93 |
Correct |
17 ms |
1956 KB |
Output is correct |
94 |
Correct |
1 ms |
208 KB |
Output is correct |
95 |
Correct |
1 ms |
208 KB |
Output is correct |
96 |
Correct |
1 ms |
208 KB |
Output is correct |
97 |
Correct |
1 ms |
208 KB |
Output is correct |
98 |
Correct |
1 ms |
208 KB |
Output is correct |
99 |
Correct |
1 ms |
208 KB |
Output is correct |
100 |
Correct |
1 ms |
208 KB |
Output is correct |
101 |
Correct |
1 ms |
208 KB |
Output is correct |
102 |
Correct |
1 ms |
208 KB |
Output is correct |
103 |
Correct |
1 ms |
208 KB |
Output is correct |
104 |
Correct |
1549 ms |
1820 KB |
Output is correct |
105 |
Correct |
1754 ms |
1992 KB |
Output is correct |
106 |
Correct |
1780 ms |
2000 KB |
Output is correct |
107 |
Correct |
1858 ms |
1952 KB |
Output is correct |
108 |
Correct |
1762 ms |
2076 KB |
Output is correct |
109 |
Correct |
1915 ms |
1992 KB |
Output is correct |
110 |
Correct |
1812 ms |
1992 KB |
Output is correct |
111 |
Correct |
1710 ms |
2060 KB |
Output is correct |
112 |
Correct |
1631 ms |
1992 KB |
Output is correct |
113 |
Correct |
1598 ms |
1992 KB |
Output is correct |
114 |
Correct |
1908 ms |
2076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1352 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |