#include <cstdio>
#ifdef DEBUG
#define D(X) X
#else
#define D(X)
#endif
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pi 3.14159265359
#define pub push_back
#define pob pop_back
#define pari pair<int,int>
#define parli pair<long, long>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const ll INF2 = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
bool comp(vector<ll>& v1, vector<ll>& v2)
{
return v1[0] < v2[0];
}
struct seg {
vector<int> tree;
int sz;
void build(int n) {
sz = 1;
while(sz<n) {
sz *= 2;
}
tree.resize(2*sz + 1, 0);
}
void clean()
{
for(int i=0; i<tree.size(); i++) {
tree[i] = 0;
}
}
void recSet(int idx, int lx, int rx, int i, int val) {
if(rx-lx==1) {
tree[idx] = val;
return;
}
int mid = (lx+rx)/2;
if(i<mid) {
recSet(2*idx+1, lx, mid, i, val);
} else
{
recSet(2*idx+2, mid, rx, i, val);
}
tree[idx] = max(tree[2*idx+1], tree[2*idx+2]);
}
void setX(int i, int val) {
recSet(0, 0, sz, i, val);
}
int rec_range(int idx, int lx, int rx, int l, int r) {
if(lx>=l&&rx<=r) {
return tree[idx];
}
if(rx<=l||lx>=r) return 0;
int mid = (lx+rx)/2;
int left = rec_range(2*idx+1, lx, mid, l, r);
int right = rec_range(2*idx+2, mid, rx, l, r);
return max(left, right);
}
int range(int l, int r) {
return rec_range(0, 0, sz, l, r);
}
};
vector<int> dp;
seg mint, maxt;
map<int, int> ord;
vector<int> h;
int res = 0;
void init2(int l, int r, int d)
{
int n = h.size();
res = 0;
for(int i=0; i<=n; i++) {
dp[i] = 0;
}
vector<int> used(n+1, 0);
vector<int> nums;
for(int i=l; i<=r; i++) {
int f1 = 0, f2 = 0;
nums.pub(h[i]);
nums.pub(h[i]-d);
nums.pub(h[i]+d);
if(i>l) {
if(h[i]>=h[i-1]) {
f1 = 1;
} else
{
f1 = 2;
}
}
if(i<r) {
if(h[i]>=h[i+1]) {
f2 = 1;
} else
{
f2 = 2;
}
}
if(f1==0) {
f1 = f2;
}
if(f2==0) {
f2 = f1;
}
if(f1==f2) {
used[i] = f1;
}
}
sort(nums.begin(), nums.end());
ord.clear();
ord[nums[0]] = 0;
int sz = nums.size();
for(int i=1; i<sz; i++) {
if(nums[i]>nums[i-1]) {
ord[nums[i]] = ord[nums[i-1]] + 1;
} else
{
ord[nums[i]] = ord[nums[i-1]];
}
}
mint.clean();
maxt.clean();
mint.build(sz);
maxt.build(sz);
for(int i=r; i>=l; i--) {
if(used[i]==0) {
continue;
}
if(used[i]==1&&h[i]-d>0) {
dp[i] = mint.range(0, ord[h[i]-d] + 1);
maxt.setX(ord[h[i]], dp[i]);
}
if(used[i]==2) {
dp[i] = 1 + maxt.range(ord[h[i]+d], sz);
mint.setX(ord[h[i]], dp[i]);
}
res = max(res, dp[i]);
}
}
void init(int n, vector<int> h2)
{
h.resize(n);
for(int i=0; i<n; i++) {
h[i] = h2[i];
}
dp.resize(n+1);
init2(0, n - 1, 1);
}
int max_towers(int l, int r, int d)
{
init2(l, r, d);
if(l==0&&r==h.size()-1) {
return res;
}
return res;
}
/*
4 0 3 20
0 1 2
1 2 3
18 1 19
*/
/*
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//D(freopen("input.txt","r",stdin);)
//D(freopen("ouput.txt","w",stdout);)
int t = 1;
//cin >> t;
loop:
while(t--)
{
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++) {
cin >> a[i];
}
init(n, a);
int res = max_towers(1, 5, 10);
if(res==0) {
res = 1;
}
cout << res;
}
return 0;
}
*/
Compilation message
towers.cpp: In member function 'void seg::clean()':
towers.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0; i<tree.size(); i++) {
| ~^~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:178:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
178 | if(l==0&&r==h.size()-1) {
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4077 ms |
15592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
904 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
856 KB |
Output is correct |
14 |
Correct |
2 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
4 ms |
1112 KB |
Output is correct |
22 |
Correct |
4 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
3 ms |
856 KB |
Output is correct |
29 |
Correct |
4 ms |
856 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
4 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
904 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
856 KB |
Output is correct |
14 |
Correct |
2 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
4 ms |
1112 KB |
Output is correct |
22 |
Correct |
4 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
3 ms |
856 KB |
Output is correct |
29 |
Correct |
4 ms |
856 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
4 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
36 |
Correct |
115 ms |
15504 KB |
Output is correct |
37 |
Correct |
207 ms |
25752 KB |
Output is correct |
38 |
Correct |
186 ms |
25864 KB |
Output is correct |
39 |
Correct |
220 ms |
25792 KB |
Output is correct |
40 |
Correct |
217 ms |
25728 KB |
Output is correct |
41 |
Correct |
333 ms |
26212 KB |
Output is correct |
42 |
Correct |
203 ms |
25704 KB |
Output is correct |
43 |
Correct |
128 ms |
26236 KB |
Output is correct |
44 |
Correct |
96 ms |
25664 KB |
Output is correct |
45 |
Correct |
88 ms |
25764 KB |
Output is correct |
46 |
Correct |
100 ms |
25800 KB |
Output is correct |
47 |
Correct |
217 ms |
25976 KB |
Output is correct |
48 |
Correct |
216 ms |
25708 KB |
Output is correct |
49 |
Correct |
212 ms |
25704 KB |
Output is correct |
50 |
Correct |
118 ms |
25752 KB |
Output is correct |
51 |
Correct |
112 ms |
25864 KB |
Output is correct |
52 |
Correct |
349 ms |
27528 KB |
Output is correct |
53 |
Correct |
408 ms |
27352 KB |
Output is correct |
54 |
Correct |
429 ms |
28496 KB |
Output is correct |
55 |
Correct |
162 ms |
27328 KB |
Output is correct |
56 |
Correct |
160 ms |
27380 KB |
Output is correct |
57 |
Correct |
298 ms |
26912 KB |
Output is correct |
58 |
Correct |
335 ms |
28480 KB |
Output is correct |
59 |
Correct |
353 ms |
27608 KB |
Output is correct |
60 |
Correct |
459 ms |
27388 KB |
Output is correct |
61 |
Correct |
399 ms |
28468 KB |
Output is correct |
62 |
Correct |
404 ms |
27352 KB |
Output is correct |
63 |
Correct |
373 ms |
27556 KB |
Output is correct |
64 |
Correct |
180 ms |
27476 KB |
Output is correct |
65 |
Correct |
168 ms |
27380 KB |
Output is correct |
66 |
Correct |
183 ms |
27420 KB |
Output is correct |
67 |
Correct |
191 ms |
27532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
26256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4038 ms |
7376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
904 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
2 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
856 KB |
Output is correct |
14 |
Correct |
2 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
4 ms |
1112 KB |
Output is correct |
22 |
Correct |
4 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
3 ms |
856 KB |
Output is correct |
29 |
Correct |
4 ms |
856 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
4 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
36 |
Correct |
115 ms |
15504 KB |
Output is correct |
37 |
Correct |
207 ms |
25752 KB |
Output is correct |
38 |
Correct |
186 ms |
25864 KB |
Output is correct |
39 |
Correct |
220 ms |
25792 KB |
Output is correct |
40 |
Correct |
217 ms |
25728 KB |
Output is correct |
41 |
Correct |
333 ms |
26212 KB |
Output is correct |
42 |
Correct |
203 ms |
25704 KB |
Output is correct |
43 |
Correct |
128 ms |
26236 KB |
Output is correct |
44 |
Correct |
96 ms |
25664 KB |
Output is correct |
45 |
Correct |
88 ms |
25764 KB |
Output is correct |
46 |
Correct |
100 ms |
25800 KB |
Output is correct |
47 |
Correct |
217 ms |
25976 KB |
Output is correct |
48 |
Correct |
216 ms |
25708 KB |
Output is correct |
49 |
Correct |
212 ms |
25704 KB |
Output is correct |
50 |
Correct |
118 ms |
25752 KB |
Output is correct |
51 |
Correct |
112 ms |
25864 KB |
Output is correct |
52 |
Correct |
349 ms |
27528 KB |
Output is correct |
53 |
Correct |
408 ms |
27352 KB |
Output is correct |
54 |
Correct |
429 ms |
28496 KB |
Output is correct |
55 |
Correct |
162 ms |
27328 KB |
Output is correct |
56 |
Correct |
160 ms |
27380 KB |
Output is correct |
57 |
Correct |
298 ms |
26912 KB |
Output is correct |
58 |
Correct |
335 ms |
28480 KB |
Output is correct |
59 |
Correct |
353 ms |
27608 KB |
Output is correct |
60 |
Correct |
459 ms |
27388 KB |
Output is correct |
61 |
Correct |
399 ms |
28468 KB |
Output is correct |
62 |
Correct |
404 ms |
27352 KB |
Output is correct |
63 |
Correct |
373 ms |
27556 KB |
Output is correct |
64 |
Correct |
180 ms |
27476 KB |
Output is correct |
65 |
Correct |
168 ms |
27380 KB |
Output is correct |
66 |
Correct |
183 ms |
27420 KB |
Output is correct |
67 |
Correct |
191 ms |
27532 KB |
Output is correct |
68 |
Execution timed out |
4027 ms |
26256 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4077 ms |
15592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |