# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863562 | prohacker | Global Warming (CEOI18_glo) | C++14 | 132 ms | 9672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
int a[N],n,r[N],bit[4*N];
int m;
vector<int> pos = {};
int b[N],ans;
void pre_calc() {
for(int i = 0 ; i <= n ; i++) {
pos.push_back(a[i]+1);
pos.push_back(a[i]);
pos.push_back(a[i]-m+1);
}
sort(pos.begin(),pos.end());
pos.resize(unique(pos.begin(),pos.end())-pos.begin());
}
int get_val(int x) {
return lower_bound(pos.begin(),pos.end(),x)-pos.begin()+1;
}
void update(int id, int val) {
while(id > 0) {
bit[id] = max(bit[id],val);
id -= (id & (-id));
}
}
int get(int id) {
int res = 0;
while(id <= N) {
res = max(res,bit[id]);
id += (id & (-id));
}
return res;
}
signed main()
{
if (fopen("CLO.inp", "r")) {
freopen("CLO.inp", "r", stdin);
freopen("CLO.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
pre_calc();
for(int i = n ; i >= 1 ; i--) {
int id = get_val(a[i]-m+1);
r[i] = get(id)+1;
int id2 = get_val(a[i]);
id = get_val(a[i]+1);
update(id2,get(id)+1);
}
for(int i = 1, res = 0 ; i <= n ; i++) {
int id = lower_bound(b+1,b+res+1,a[i])-b;
b[id] = a[i];
res = max(res,id);
ans = max(ans,id+r[i]-1);
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |