# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
888450 |
2023-12-17T12:46:26 Z |
kim |
Global Warming (CEOI18_glo) |
C++17 |
|
102 ms |
6604 KB |
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
int dp[200005],a[200005],dpL[200005],dpR[200005];
struct fenwick{
vector<int> bit;
void init(int n){bit=vector<int>(n);}
void upd(int i,int x){
for(;i<bit.size();i+=i&-i) bit[i]=max(bit[i],x);
}
int qr(int i){
int ret=0;
for(;i>0;i-=i&-i) ret=max(ret,bit[i]);
return ret;
}
}fw;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,d; cin>>n>>d;
int cnt=0;
for(int i=1;i<=n;++i){
cin>>a[i];
int id=lower_bound(dp,dp+cnt,a[i])-dp;
if(id==cnt) ++cnt;
dp[id]=a[i];
dpL[i]=id+1;
}
cnt=0;
for(int i=n;i>=1;--i){
int id=lower_bound(dp,dp+cnt,-a[i])-dp;
if(id==cnt) ++cnt;
dp[id]=-a[i];
dpR[i]=id+1;
}
vector<int> comp;
for(int i=1;i<=n;++i) comp.eb(a[i]-d);
sort(comp.begin(),comp.end());
comp.erase(unique(comp.begin(),comp.end()),comp.end());
fw.init(comp.size()+5);
int ans=0;
for(int i=1;i<=n;++i){
ans=max(ans,dpR[i]+fw.qr(lower_bound(comp.begin(),comp.end(),a[i])-comp.begin()));
fw.upd(lower_bound(comp.begin(),comp.end(),a[i]-d)-comp.begin()+1,dpL[i]);
}
cout<<ans;
return 0;
}
Compilation message
glo.cpp: In member function 'void fenwick::upd(int, int)':
glo.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(;i<bit.size();i+=i&-i) bit[i]=max(bit[i],x);
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2508 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2508 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
6436 KB |
Output is correct |
2 |
Correct |
99 ms |
6352 KB |
Output is correct |
3 |
Correct |
96 ms |
6352 KB |
Output is correct |
4 |
Correct |
95 ms |
6432 KB |
Output is correct |
5 |
Correct |
45 ms |
5340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3548 KB |
Output is correct |
2 |
Correct |
22 ms |
3552 KB |
Output is correct |
3 |
Correct |
22 ms |
3552 KB |
Output is correct |
4 |
Correct |
12 ms |
3416 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
11 ms |
3420 KB |
Output is correct |
7 |
Correct |
18 ms |
3548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
4564 KB |
Output is correct |
2 |
Correct |
39 ms |
4572 KB |
Output is correct |
3 |
Correct |
85 ms |
6412 KB |
Output is correct |
4 |
Correct |
42 ms |
5336 KB |
Output is correct |
5 |
Correct |
27 ms |
4316 KB |
Output is correct |
6 |
Correct |
37 ms |
5836 KB |
Output is correct |
7 |
Correct |
42 ms |
6464 KB |
Output is correct |
8 |
Correct |
32 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2508 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
96 ms |
6436 KB |
Output is correct |
28 |
Correct |
99 ms |
6352 KB |
Output is correct |
29 |
Correct |
96 ms |
6352 KB |
Output is correct |
30 |
Correct |
95 ms |
6432 KB |
Output is correct |
31 |
Correct |
45 ms |
5340 KB |
Output is correct |
32 |
Correct |
22 ms |
3548 KB |
Output is correct |
33 |
Correct |
22 ms |
3552 KB |
Output is correct |
34 |
Correct |
22 ms |
3552 KB |
Output is correct |
35 |
Correct |
12 ms |
3416 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
11 ms |
3420 KB |
Output is correct |
38 |
Correct |
18 ms |
3548 KB |
Output is correct |
39 |
Correct |
40 ms |
4564 KB |
Output is correct |
40 |
Correct |
39 ms |
4572 KB |
Output is correct |
41 |
Correct |
85 ms |
6412 KB |
Output is correct |
42 |
Correct |
42 ms |
5336 KB |
Output is correct |
43 |
Correct |
27 ms |
4316 KB |
Output is correct |
44 |
Correct |
37 ms |
5836 KB |
Output is correct |
45 |
Correct |
42 ms |
6464 KB |
Output is correct |
46 |
Correct |
32 ms |
4560 KB |
Output is correct |
47 |
Correct |
46 ms |
4320 KB |
Output is correct |
48 |
Correct |
45 ms |
4560 KB |
Output is correct |
49 |
Correct |
102 ms |
6428 KB |
Output is correct |
50 |
Correct |
46 ms |
5332 KB |
Output is correct |
51 |
Correct |
42 ms |
5084 KB |
Output is correct |
52 |
Correct |
54 ms |
6292 KB |
Output is correct |
53 |
Correct |
40 ms |
6084 KB |
Output is correct |
54 |
Correct |
44 ms |
6604 KB |
Output is correct |
55 |
Correct |
82 ms |
6348 KB |
Output is correct |