#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010 * 2;
const long long inf = 2e9 ;
int arr[MAX] , arr2[MAX] , len[MAX] , tree[4 * MAX] ;
void update(int node , int l , int r , int idx , int val)
{
if(l > idx || r < idx)
return ;
if(l == r)
{
tree[node] = max(tree[node] , val);
return ;
}
int mid = (l + r) >> 1 ;
update(node << 1 , l , mid , idx , val) ;
update(node << 1 | 1 , mid + 1 , r , idx , val) ;
tree[node] = max(tree[node << 1] , tree[node << 1 | 1]);
}
int query(int node , int l , int r , int x , int y)
{
if(x > r || y < l)
return 0 ;
if(l >= x && r <= y)
return tree[node] ;
int mid = (l + r) >> 1 ;
int a = query(node << 1 , l , mid , x , y) ;
int b = query(node << 1 | 1 , mid + 1 , r , x , y) ;
return max(a , b) ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0) ;
int n , x ;
cin>>n>>x ;
vector< pair<int , int> >vp ;
for(int i = 1 ; i <= n ; ++i)
{
cin>>arr2[i] ;
arr2[i] += x ;
vp.push_back({arr2[i] , i}) ;
vp.push_back({arr2[i]-x , n+i});
}
sort(vp.begin() , vp.end());
int idx = 1 ;
for(int i = 0 ; i < vp.size() ; ++i)
{
if(i != 0)
{
if(vp[i].first == vp[i-1].first)
--idx;
}
arr[vp[i].second] = idx ;
idx++ ;
}
int ans = 0 ;
for(int i = n ; i > 0 ; --i)
{
len[i+n] = query(1 , 1 , n*2+1 , arr[i+n] + 1 , n*2+1) ;
int a = query(1 , 1 , n * 2 + 1 , arr[i]+1 , n * 2 + 1) + 1;
update(1 , 1 , n * 2 + 1 , arr[i] , a) ;
}
memset(tree , 0 , sizeof(tree));
for(int i = n+1 ; i <= n*2 ; ++i)
{
int a = query(1 , 1 , n * 2 + 1 , 1 , arr[i]-1) + 1;
update(1 , 1 , n * 2 + 1 , arr[i] , a) ;
ans = max(ans , a + len[i]);
}
return cout<<ans<<"\n" , 0 ;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 0 ; i < vp.size() ; ++i)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6600 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
2 ms |
6612 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
2 ms |
6604 KB |
Output is correct |
10 |
Correct |
2 ms |
6612 KB |
Output is correct |
11 |
Correct |
3 ms |
6600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6600 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
2 ms |
6612 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
2 ms |
6604 KB |
Output is correct |
10 |
Correct |
2 ms |
6612 KB |
Output is correct |
11 |
Correct |
3 ms |
6600 KB |
Output is correct |
12 |
Correct |
2 ms |
6612 KB |
Output is correct |
13 |
Correct |
3 ms |
6612 KB |
Output is correct |
14 |
Correct |
3 ms |
6612 KB |
Output is correct |
15 |
Correct |
2 ms |
6612 KB |
Output is correct |
16 |
Correct |
3 ms |
6612 KB |
Output is correct |
17 |
Correct |
2 ms |
6604 KB |
Output is correct |
18 |
Correct |
2 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6600 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
2 ms |
6612 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
2 ms |
6604 KB |
Output is correct |
10 |
Correct |
2 ms |
6612 KB |
Output is correct |
11 |
Correct |
3 ms |
6600 KB |
Output is correct |
12 |
Correct |
2 ms |
6612 KB |
Output is correct |
13 |
Correct |
3 ms |
6612 KB |
Output is correct |
14 |
Correct |
3 ms |
6612 KB |
Output is correct |
15 |
Correct |
2 ms |
6612 KB |
Output is correct |
16 |
Correct |
3 ms |
6612 KB |
Output is correct |
17 |
Correct |
2 ms |
6604 KB |
Output is correct |
18 |
Correct |
2 ms |
6484 KB |
Output is correct |
19 |
Correct |
3 ms |
6612 KB |
Output is correct |
20 |
Correct |
3 ms |
6612 KB |
Output is correct |
21 |
Correct |
3 ms |
6612 KB |
Output is correct |
22 |
Correct |
3 ms |
6612 KB |
Output is correct |
23 |
Correct |
3 ms |
6612 KB |
Output is correct |
24 |
Correct |
3 ms |
6612 KB |
Output is correct |
25 |
Correct |
3 ms |
6612 KB |
Output is correct |
26 |
Correct |
3 ms |
6612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
14848 KB |
Output is correct |
2 |
Correct |
205 ms |
14900 KB |
Output is correct |
3 |
Correct |
211 ms |
14992 KB |
Output is correct |
4 |
Correct |
202 ms |
14788 KB |
Output is correct |
5 |
Correct |
144 ms |
14084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
8776 KB |
Output is correct |
2 |
Correct |
48 ms |
8776 KB |
Output is correct |
3 |
Correct |
51 ms |
8728 KB |
Output is correct |
4 |
Correct |
36 ms |
8576 KB |
Output is correct |
5 |
Correct |
2 ms |
6484 KB |
Output is correct |
6 |
Correct |
37 ms |
8504 KB |
Output is correct |
7 |
Correct |
44 ms |
8800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
10756 KB |
Output is correct |
2 |
Correct |
105 ms |
10760 KB |
Output is correct |
3 |
Correct |
230 ms |
14888 KB |
Output is correct |
4 |
Correct |
149 ms |
14132 KB |
Output is correct |
5 |
Correct |
77 ms |
10324 KB |
Output is correct |
6 |
Correct |
146 ms |
13840 KB |
Output is correct |
7 |
Correct |
141 ms |
14476 KB |
Output is correct |
8 |
Correct |
95 ms |
10812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6600 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
2 ms |
6612 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
2 ms |
6604 KB |
Output is correct |
10 |
Correct |
2 ms |
6612 KB |
Output is correct |
11 |
Correct |
3 ms |
6600 KB |
Output is correct |
12 |
Correct |
2 ms |
6612 KB |
Output is correct |
13 |
Correct |
3 ms |
6612 KB |
Output is correct |
14 |
Correct |
3 ms |
6612 KB |
Output is correct |
15 |
Correct |
2 ms |
6612 KB |
Output is correct |
16 |
Correct |
3 ms |
6612 KB |
Output is correct |
17 |
Correct |
2 ms |
6604 KB |
Output is correct |
18 |
Correct |
2 ms |
6484 KB |
Output is correct |
19 |
Correct |
3 ms |
6612 KB |
Output is correct |
20 |
Correct |
3 ms |
6612 KB |
Output is correct |
21 |
Correct |
3 ms |
6612 KB |
Output is correct |
22 |
Correct |
3 ms |
6612 KB |
Output is correct |
23 |
Correct |
3 ms |
6612 KB |
Output is correct |
24 |
Correct |
3 ms |
6612 KB |
Output is correct |
25 |
Correct |
3 ms |
6612 KB |
Output is correct |
26 |
Correct |
3 ms |
6612 KB |
Output is correct |
27 |
Correct |
222 ms |
14848 KB |
Output is correct |
28 |
Correct |
205 ms |
14900 KB |
Output is correct |
29 |
Correct |
211 ms |
14992 KB |
Output is correct |
30 |
Correct |
202 ms |
14788 KB |
Output is correct |
31 |
Correct |
144 ms |
14084 KB |
Output is correct |
32 |
Correct |
48 ms |
8776 KB |
Output is correct |
33 |
Correct |
48 ms |
8776 KB |
Output is correct |
34 |
Correct |
51 ms |
8728 KB |
Output is correct |
35 |
Correct |
36 ms |
8576 KB |
Output is correct |
36 |
Correct |
2 ms |
6484 KB |
Output is correct |
37 |
Correct |
37 ms |
8504 KB |
Output is correct |
38 |
Correct |
44 ms |
8800 KB |
Output is correct |
39 |
Correct |
100 ms |
10756 KB |
Output is correct |
40 |
Correct |
105 ms |
10760 KB |
Output is correct |
41 |
Correct |
230 ms |
14888 KB |
Output is correct |
42 |
Correct |
149 ms |
14132 KB |
Output is correct |
43 |
Correct |
77 ms |
10324 KB |
Output is correct |
44 |
Correct |
146 ms |
13840 KB |
Output is correct |
45 |
Correct |
141 ms |
14476 KB |
Output is correct |
46 |
Correct |
95 ms |
10812 KB |
Output is correct |
47 |
Correct |
99 ms |
10744 KB |
Output is correct |
48 |
Correct |
103 ms |
10804 KB |
Output is correct |
49 |
Correct |
216 ms |
14900 KB |
Output is correct |
50 |
Correct |
149 ms |
14100 KB |
Output is correct |
51 |
Correct |
110 ms |
12196 KB |
Output is correct |
52 |
Correct |
154 ms |
14148 KB |
Output is correct |
53 |
Correct |
146 ms |
14148 KB |
Output is correct |
54 |
Correct |
149 ms |
14820 KB |
Output is correct |
55 |
Correct |
183 ms |
14936 KB |
Output is correct |