#include <vector>
#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;
#define vi vector<int>
#include <set>
vi st;
const int siz = 1e5;
int h[siz];
int d;
#define pi pair<int,int>
#pragma warning(disable : 4996)
struct node {
int l, r, mid, maxi,ans,repl,repr;
node* sl, * sr,*t=NULL;
node(int li, int ri) {
l = li, r = ri, mid = (l + r) / 2;
if (l < r) {
sl = new node(l, mid);
sr = new node(mid + 1, r);
maxi = max(sl->maxi, sr->maxi);
}
else {
maxi = h[l];
ans = 1;
repl = l, repr=l;
}
}
int qm(int a, int b) {
if (a > b)return 0;
if (a > r || b < l)return 0;
if (a <= l && b >= r)return maxi;
return max(sl->qm(a, b), sr->qm(a, b));
}
void calc(node* top) {
t = top;
if (l < r) {
sl->calc(top), sr->calc(top);
int l1 = sl->repr, r1 = sr->repl;
if (t->qm(l1 + 1, r1 - 1) - d >= max(h[l1], h[r1])) {
ans = sl->ans + sr->ans;
repl = sl->repl;
repr = sr->repr;
}
else {
ans = sl->ans - 1 + sr->ans;
if (sl->repl == l1 && h[l1] > h[r1]) {
repl = sr->repl, repr = sr->repr;
}
else if (r1 == sr->repr && h[r1] > h[l1]) {
repl = sl->repl, repr = sl->repr;
}
else {
repl = sl->repl, repr = sr->repr;
}
}
}
}
int query(int a, int b, int &rep) {
if (a > r || b < l)return 0;
if (a <= l && b >= r) {
if (rep != -1) {
int l1 = rep, r1 = repl;
if (t->qm(l1 + 1, r1 - 1) - d >= max(h[l1], h[r1])) {
rep = repr;
return ans;
}
else {
if (repl != repr || h[repl] < h[rep]) {
rep = repr;
}
return ans - 1;
}
}
else {
rep = repr;
return ans;
}
}
else {
return sl->query(a, b, rep) + sr->query(a, b, rep);
}
}
};
node* seg;
void init(int N, std::vector<int> H) {
for (int i = 0; i < N; i++)h[i] = H[i];
seg = new node(0, N - 1);
/*set<int> s;
multiset<pi> d;
for (int i = 0; i < N; i++)s.insert(i);
for (int i = 0; i < N; i++)d.insert({ 0,i });
while (s.size()>1) {
auto it = d.begin(); pi p = *it;
if(d.fi)
}*/
}
bool f = 0;
int max_towers(int L, int R, int D) {
if (f == 0) {
f = 1;
d = D;
seg->calc(seg);
}
int k = -1;
return seg->query(L, R, k);
}
/*
int main() {
int N, Q;
assert(2 == scanf("%d %d", &N, &Q));
std::vector<int> H(N);
for (int i = 0; i < N; ++i) {
assert(1 == scanf("%d", &H[i]));
}
init(N, H);
for (int i = 0; i < Q; ++i) {
int L, R, D;
assert(3 == scanf("%d %d %d", &L, &R, &D));
printf("%d\n", max_towers(L, R, D));
}
return 0;
}*/
Compilation message
towers.cpp:14: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
14 | #pragma warning(disable : 4996)
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
433 ms |
8536 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
36 |
Correct |
14 ms |
9140 KB |
Output is correct |
37 |
Correct |
25 ms |
13876 KB |
Output is correct |
38 |
Correct |
23 ms |
13880 KB |
Output is correct |
39 |
Correct |
24 ms |
13884 KB |
Output is correct |
40 |
Correct |
25 ms |
13880 KB |
Output is correct |
41 |
Correct |
27 ms |
13888 KB |
Output is correct |
42 |
Correct |
28 ms |
13980 KB |
Output is correct |
43 |
Correct |
23 ms |
13888 KB |
Output is correct |
44 |
Correct |
20 ms |
13884 KB |
Output is correct |
45 |
Correct |
24 ms |
14036 KB |
Output is correct |
46 |
Correct |
21 ms |
13880 KB |
Output is correct |
47 |
Correct |
26 ms |
13876 KB |
Output is correct |
48 |
Correct |
22 ms |
13884 KB |
Output is correct |
49 |
Correct |
22 ms |
13884 KB |
Output is correct |
50 |
Correct |
23 ms |
13884 KB |
Output is correct |
51 |
Correct |
28 ms |
13888 KB |
Output is correct |
52 |
Correct |
27 ms |
13872 KB |
Output is correct |
53 |
Correct |
27 ms |
13880 KB |
Output is correct |
54 |
Correct |
27 ms |
13872 KB |
Output is correct |
55 |
Correct |
21 ms |
14024 KB |
Output is correct |
56 |
Correct |
23 ms |
13876 KB |
Output is correct |
57 |
Correct |
25 ms |
13620 KB |
Output is correct |
58 |
Correct |
25 ms |
13880 KB |
Output is correct |
59 |
Correct |
23 ms |
13884 KB |
Output is correct |
60 |
Correct |
27 ms |
13884 KB |
Output is correct |
61 |
Correct |
25 ms |
13860 KB |
Output is correct |
62 |
Correct |
27 ms |
13876 KB |
Output is correct |
63 |
Correct |
23 ms |
13876 KB |
Output is correct |
64 |
Correct |
23 ms |
13884 KB |
Output is correct |
65 |
Correct |
21 ms |
13888 KB |
Output is correct |
66 |
Correct |
24 ms |
13884 KB |
Output is correct |
67 |
Correct |
21 ms |
13888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
13880 KB |
Output is correct |
2 |
Correct |
851 ms |
13912 KB |
Output is correct |
3 |
Correct |
847 ms |
13884 KB |
Output is correct |
4 |
Correct |
879 ms |
14144 KB |
Output is correct |
5 |
Correct |
981 ms |
13880 KB |
Output is correct |
6 |
Correct |
943 ms |
13884 KB |
Output is correct |
7 |
Correct |
972 ms |
13952 KB |
Output is correct |
8 |
Correct |
935 ms |
13884 KB |
Output is correct |
9 |
Correct |
1038 ms |
14124 KB |
Output is correct |
10 |
Correct |
919 ms |
13876 KB |
Output is correct |
11 |
Correct |
1014 ms |
13880 KB |
Output is correct |
12 |
Correct |
871 ms |
13880 KB |
Output is correct |
13 |
Correct |
1002 ms |
13876 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
23 ms |
13988 KB |
Output is correct |
18 |
Correct |
23 ms |
13880 KB |
Output is correct |
19 |
Correct |
24 ms |
13876 KB |
Output is correct |
20 |
Correct |
22 ms |
13884 KB |
Output is correct |
21 |
Correct |
24 ms |
13884 KB |
Output is correct |
22 |
Correct |
22 ms |
14108 KB |
Output is correct |
23 |
Correct |
22 ms |
13888 KB |
Output is correct |
24 |
Correct |
25 ms |
13888 KB |
Output is correct |
25 |
Correct |
22 ms |
13884 KB |
Output is correct |
26 |
Correct |
23 ms |
13872 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
188 ms |
3672 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '7197' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
36 |
Correct |
14 ms |
9140 KB |
Output is correct |
37 |
Correct |
25 ms |
13876 KB |
Output is correct |
38 |
Correct |
23 ms |
13880 KB |
Output is correct |
39 |
Correct |
24 ms |
13884 KB |
Output is correct |
40 |
Correct |
25 ms |
13880 KB |
Output is correct |
41 |
Correct |
27 ms |
13888 KB |
Output is correct |
42 |
Correct |
28 ms |
13980 KB |
Output is correct |
43 |
Correct |
23 ms |
13888 KB |
Output is correct |
44 |
Correct |
20 ms |
13884 KB |
Output is correct |
45 |
Correct |
24 ms |
14036 KB |
Output is correct |
46 |
Correct |
21 ms |
13880 KB |
Output is correct |
47 |
Correct |
26 ms |
13876 KB |
Output is correct |
48 |
Correct |
22 ms |
13884 KB |
Output is correct |
49 |
Correct |
22 ms |
13884 KB |
Output is correct |
50 |
Correct |
23 ms |
13884 KB |
Output is correct |
51 |
Correct |
28 ms |
13888 KB |
Output is correct |
52 |
Correct |
27 ms |
13872 KB |
Output is correct |
53 |
Correct |
27 ms |
13880 KB |
Output is correct |
54 |
Correct |
27 ms |
13872 KB |
Output is correct |
55 |
Correct |
21 ms |
14024 KB |
Output is correct |
56 |
Correct |
23 ms |
13876 KB |
Output is correct |
57 |
Correct |
25 ms |
13620 KB |
Output is correct |
58 |
Correct |
25 ms |
13880 KB |
Output is correct |
59 |
Correct |
23 ms |
13884 KB |
Output is correct |
60 |
Correct |
27 ms |
13884 KB |
Output is correct |
61 |
Correct |
25 ms |
13860 KB |
Output is correct |
62 |
Correct |
27 ms |
13876 KB |
Output is correct |
63 |
Correct |
23 ms |
13876 KB |
Output is correct |
64 |
Correct |
23 ms |
13884 KB |
Output is correct |
65 |
Correct |
21 ms |
13888 KB |
Output is correct |
66 |
Correct |
24 ms |
13884 KB |
Output is correct |
67 |
Correct |
21 ms |
13888 KB |
Output is correct |
68 |
Correct |
672 ms |
13880 KB |
Output is correct |
69 |
Correct |
851 ms |
13912 KB |
Output is correct |
70 |
Correct |
847 ms |
13884 KB |
Output is correct |
71 |
Correct |
879 ms |
14144 KB |
Output is correct |
72 |
Correct |
981 ms |
13880 KB |
Output is correct |
73 |
Correct |
943 ms |
13884 KB |
Output is correct |
74 |
Correct |
972 ms |
13952 KB |
Output is correct |
75 |
Correct |
935 ms |
13884 KB |
Output is correct |
76 |
Correct |
1038 ms |
14124 KB |
Output is correct |
77 |
Correct |
919 ms |
13876 KB |
Output is correct |
78 |
Correct |
1014 ms |
13880 KB |
Output is correct |
79 |
Correct |
871 ms |
13880 KB |
Output is correct |
80 |
Correct |
1002 ms |
13876 KB |
Output is correct |
81 |
Correct |
0 ms |
344 KB |
Output is correct |
82 |
Correct |
1 ms |
600 KB |
Output is correct |
83 |
Correct |
1 ms |
600 KB |
Output is correct |
84 |
Correct |
23 ms |
13988 KB |
Output is correct |
85 |
Correct |
23 ms |
13880 KB |
Output is correct |
86 |
Correct |
24 ms |
13876 KB |
Output is correct |
87 |
Correct |
22 ms |
13884 KB |
Output is correct |
88 |
Correct |
24 ms |
13884 KB |
Output is correct |
89 |
Correct |
22 ms |
14108 KB |
Output is correct |
90 |
Correct |
22 ms |
13888 KB |
Output is correct |
91 |
Correct |
25 ms |
13888 KB |
Output is correct |
92 |
Correct |
22 ms |
13884 KB |
Output is correct |
93 |
Correct |
23 ms |
13872 KB |
Output is correct |
94 |
Correct |
1 ms |
600 KB |
Output is correct |
95 |
Correct |
1 ms |
600 KB |
Output is correct |
96 |
Correct |
1 ms |
600 KB |
Output is correct |
97 |
Correct |
1 ms |
600 KB |
Output is correct |
98 |
Correct |
1 ms |
600 KB |
Output is correct |
99 |
Correct |
1 ms |
600 KB |
Output is correct |
100 |
Correct |
1 ms |
600 KB |
Output is correct |
101 |
Correct |
1 ms |
600 KB |
Output is correct |
102 |
Correct |
1 ms |
600 KB |
Output is correct |
103 |
Correct |
1 ms |
600 KB |
Output is correct |
104 |
Correct |
773 ms |
12556 KB |
Output is correct |
105 |
Correct |
983 ms |
13888 KB |
Output is correct |
106 |
Correct |
1096 ms |
13892 KB |
Output is correct |
107 |
Correct |
1016 ms |
13888 KB |
Output is correct |
108 |
Correct |
1104 ms |
13888 KB |
Output is correct |
109 |
Correct |
1036 ms |
13884 KB |
Output is correct |
110 |
Correct |
904 ms |
13912 KB |
Output is correct |
111 |
Correct |
941 ms |
13876 KB |
Output is correct |
112 |
Correct |
937 ms |
13888 KB |
Output is correct |
113 |
Correct |
877 ms |
13876 KB |
Output is correct |
114 |
Correct |
968 ms |
13912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
433 ms |
8536 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |