Submission #633207

# Submission time Handle Problem Language Result Execution time Memory
633207 2022-08-21T22:48:41 Z EthanKim8683 Global Warming (CEOI18_glo) C++17
100 / 100
216 ms 23868 KB
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

using I=int;
using B=bool;

const I N=200000;

I t_arr[N];
multiset<I>liss[N+1];
vector<pair<I,I>>adds;
vector<I>dp1;
vector<I>dp2;
I n,x;

void cmb(I& a,I b){
  a=max(a,b);
}

void add(I len,I las){
  liss[len].insert(las);
  adds.push_back({len,las});
}

void rem(){
  auto[len,las]=adds.back();
  adds.pop_back();
  liss[len].erase(liss[len].find(las));
}

B chk(I i,I las){
  return liss[i].size()&&liss[i].begin()!=liss[i].upper_bound(las+x-1);
}

I fnd(I las){
  I l=0,r=n;
  while(l<r){
    I m=l+(r-l+1)/2;
    if(chk(m,las))l=m;
    else r=m-1;
  }
  return r;
}

I main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>x;
  for(I i=0;i<n;i++)cin>>t_arr[i];
  for(I i=0;i<n;i++){
    I t=t_arr[i];
    auto it=lower_bound(dp1.begin(),dp1.end(),t);
    I len;
    if(it==dp1.end())dp1.push_back(t),len=dp1.size();
    else len=it-dp1.begin()+1,*it=t;
    add(len,t);
  }
  I res=0;
  for(I i=n-1;i>=0;i--){
    I t=t_arr[i];
    auto it=lower_bound(dp2.begin(),dp2.end(),t,greater<I>());
    I len;
    if(it==dp2.end())dp2.push_back(t),len=dp2.size();
    else len=it-dp2.begin()+1,*it=t;
    rem(),res=max(res,fnd(t)+len);
  }
  printf("%i\n",res);
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9616 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9616 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9616 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9728 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9724 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 5 ms 9700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 21392 KB Output is correct
2 Correct 216 ms 21428 KB Output is correct
3 Correct 215 ms 21432 KB Output is correct
4 Correct 205 ms 21360 KB Output is correct
5 Correct 90 ms 22720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 12620 KB Output is correct
2 Correct 42 ms 12624 KB Output is correct
3 Correct 42 ms 12576 KB Output is correct
4 Correct 29 ms 12808 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 19 ms 12928 KB Output is correct
7 Correct 36 ms 13132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15680 KB Output is correct
2 Correct 58 ms 15576 KB Output is correct
3 Correct 125 ms 21460 KB Output is correct
4 Correct 79 ms 22744 KB Output is correct
5 Correct 40 ms 15744 KB Output is correct
6 Correct 69 ms 21176 KB Output is correct
7 Correct 75 ms 21252 KB Output is correct
8 Correct 48 ms 15564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9616 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9728 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9724 KB Output is correct
24 Correct 6 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 5 ms 9700 KB Output is correct
27 Correct 212 ms 21392 KB Output is correct
28 Correct 216 ms 21428 KB Output is correct
29 Correct 215 ms 21432 KB Output is correct
30 Correct 205 ms 21360 KB Output is correct
31 Correct 90 ms 22720 KB Output is correct
32 Correct 43 ms 12620 KB Output is correct
33 Correct 42 ms 12624 KB Output is correct
34 Correct 42 ms 12576 KB Output is correct
35 Correct 29 ms 12808 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 19 ms 12928 KB Output is correct
38 Correct 36 ms 13132 KB Output is correct
39 Correct 59 ms 15680 KB Output is correct
40 Correct 58 ms 15576 KB Output is correct
41 Correct 125 ms 21460 KB Output is correct
42 Correct 79 ms 22744 KB Output is correct
43 Correct 40 ms 15744 KB Output is correct
44 Correct 69 ms 21176 KB Output is correct
45 Correct 75 ms 21252 KB Output is correct
46 Correct 48 ms 15564 KB Output is correct
47 Correct 91 ms 16516 KB Output is correct
48 Correct 91 ms 16472 KB Output is correct
49 Correct 213 ms 23316 KB Output is correct
50 Correct 88 ms 23868 KB Output is correct
51 Correct 47 ms 19768 KB Output is correct
52 Correct 61 ms 23100 KB Output is correct
53 Correct 71 ms 22992 KB Output is correct
54 Correct 81 ms 23740 KB Output is correct
55 Correct 162 ms 23404 KB Output is correct