#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "towers.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 1e5 + 5;
int n, m;
int a[SIZE];
vector<int> lis;
void init(int N, vector<int> H) {
n = N;
FOR (i, 0, n - 1) a[i] = H[i], lis.pb(a[i]);
sort(lis.begin(), lis.end());
lis.erase(unique(lis.begin(), lis.end()), lis.end());
m = lis.size();
}
int bit[SIZE];
void upd(int pos, int x) {
for (; pos <= m; pos += pos & -pos) bit[pos] = max(bit[pos], x);
}
int que(int pos) {
int re = 0;
for (; pos; pos -= pos & -pos) re = max(re, bit[pos]);
return re;
}
int bit2[SIZE];
void upd2(int pos, int x) {
for (; pos; pos -= pos & -pos) bit2[pos] = max(bit2[pos], x);
}
int que2(int pos) {
int re = 0;
for (; pos <= m; pos += pos & -pos) re = max(re, bit2[pos]);
return re;
}
int dp[SIZE];
int max_towers(int L, int R, int D) {
fill(bit + 1, bit + n + 1, 0);
fill(bit2 + 1, bit2 + n + 1, 0);
FOR (i, L, R) {
int pos = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin() + 1;
dp[i] = que2(pos) + 1;
upd(pos, dp[i]);
pos = upper_bound(lis.begin(), lis.end(), a[i] - D) - lis.begin();
upd2(pos, que(pos));
debug(i, dp[i]);
}
return *max_element(dp + L, dp + R + 1);
}
/*
in1
7 3
10 20 60 40 50 30 70
1 5 10
2 2 100
0 6 17
out1
3
1
2
*/
#ifdef WAIMAI
int main() {
int N, Q;
assert(2 == scanf("%d %d", &N, &Q));
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;
}
#endif
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:16:20: warning: statement has no effect [-Wunused-value]
16 | #define debug(...) 7122
| ^~~~
towers.cpp:70:9: note: in expansion of macro 'debug'
70 | debug(i, dp[i]);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4085 ms |
1836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
15 ms |
1708 KB |
Output is correct |
37 |
Correct |
22 ms |
2496 KB |
Output is correct |
38 |
Correct |
18 ms |
2380 KB |
Output is correct |
39 |
Correct |
21 ms |
2456 KB |
Output is correct |
40 |
Correct |
18 ms |
2348 KB |
Output is correct |
41 |
Correct |
33 ms |
2636 KB |
Output is correct |
42 |
Correct |
16 ms |
2368 KB |
Output is correct |
43 |
Correct |
17 ms |
2488 KB |
Output is correct |
44 |
Correct |
12 ms |
2336 KB |
Output is correct |
45 |
Correct |
11 ms |
2368 KB |
Output is correct |
46 |
Correct |
13 ms |
2356 KB |
Output is correct |
47 |
Correct |
25 ms |
2480 KB |
Output is correct |
48 |
Correct |
27 ms |
2368 KB |
Output is correct |
49 |
Correct |
17 ms |
2348 KB |
Output is correct |
50 |
Correct |
13 ms |
2456 KB |
Output is correct |
51 |
Correct |
16 ms |
2524 KB |
Output is correct |
52 |
Correct |
48 ms |
2712 KB |
Output is correct |
53 |
Correct |
41 ms |
2756 KB |
Output is correct |
54 |
Correct |
40 ms |
2736 KB |
Output is correct |
55 |
Correct |
25 ms |
2672 KB |
Output is correct |
56 |
Correct |
25 ms |
2744 KB |
Output is correct |
57 |
Correct |
34 ms |
2604 KB |
Output is correct |
58 |
Correct |
41 ms |
2772 KB |
Output is correct |
59 |
Correct |
49 ms |
2752 KB |
Output is correct |
60 |
Correct |
46 ms |
2836 KB |
Output is correct |
61 |
Correct |
39 ms |
2728 KB |
Output is correct |
62 |
Correct |
37 ms |
2748 KB |
Output is correct |
63 |
Correct |
44 ms |
2736 KB |
Output is correct |
64 |
Correct |
21 ms |
2752 KB |
Output is correct |
65 |
Correct |
21 ms |
2720 KB |
Output is correct |
66 |
Correct |
23 ms |
2652 KB |
Output is correct |
67 |
Correct |
21 ms |
2724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4010 ms |
2760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4075 ms |
1080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
15 ms |
1708 KB |
Output is correct |
37 |
Correct |
22 ms |
2496 KB |
Output is correct |
38 |
Correct |
18 ms |
2380 KB |
Output is correct |
39 |
Correct |
21 ms |
2456 KB |
Output is correct |
40 |
Correct |
18 ms |
2348 KB |
Output is correct |
41 |
Correct |
33 ms |
2636 KB |
Output is correct |
42 |
Correct |
16 ms |
2368 KB |
Output is correct |
43 |
Correct |
17 ms |
2488 KB |
Output is correct |
44 |
Correct |
12 ms |
2336 KB |
Output is correct |
45 |
Correct |
11 ms |
2368 KB |
Output is correct |
46 |
Correct |
13 ms |
2356 KB |
Output is correct |
47 |
Correct |
25 ms |
2480 KB |
Output is correct |
48 |
Correct |
27 ms |
2368 KB |
Output is correct |
49 |
Correct |
17 ms |
2348 KB |
Output is correct |
50 |
Correct |
13 ms |
2456 KB |
Output is correct |
51 |
Correct |
16 ms |
2524 KB |
Output is correct |
52 |
Correct |
48 ms |
2712 KB |
Output is correct |
53 |
Correct |
41 ms |
2756 KB |
Output is correct |
54 |
Correct |
40 ms |
2736 KB |
Output is correct |
55 |
Correct |
25 ms |
2672 KB |
Output is correct |
56 |
Correct |
25 ms |
2744 KB |
Output is correct |
57 |
Correct |
34 ms |
2604 KB |
Output is correct |
58 |
Correct |
41 ms |
2772 KB |
Output is correct |
59 |
Correct |
49 ms |
2752 KB |
Output is correct |
60 |
Correct |
46 ms |
2836 KB |
Output is correct |
61 |
Correct |
39 ms |
2728 KB |
Output is correct |
62 |
Correct |
37 ms |
2748 KB |
Output is correct |
63 |
Correct |
44 ms |
2736 KB |
Output is correct |
64 |
Correct |
21 ms |
2752 KB |
Output is correct |
65 |
Correct |
21 ms |
2720 KB |
Output is correct |
66 |
Correct |
23 ms |
2652 KB |
Output is correct |
67 |
Correct |
21 ms |
2724 KB |
Output is correct |
68 |
Execution timed out |
4010 ms |
2760 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4085 ms |
1836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |