# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282765 | doowey | Global Warming (CEOI18_glo) | C++14 | 68 ms | 8748 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>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = (ll)1e10;
int main(){
fastIO;
int n;
ll x;
cin >> n >> x;
vector<ll> v(n);
for(int i = 0 ; i < n; i ++ ){
cin >> v[i];
}
vector<int> g;
vector<pii> nx;
int res = 1;
int mid, l, r;
int sh;
for(int i = n-1; i >= 0 ; i -- ){
sh = v[i];
l = 0, r = (int)g.size();
while(l < r){
mid = (l + r) / 2;
if(g[mid] <= sh)
r = mid;
else
l = mid + 1;
}
if(l == g.size()){
nx.push_back(mp(sh, -1));
g.push_back(sh);
}
else{
nx.push_back(mp(g[l], l));
g[l]=sh;
}
}
vector<int> cc;
int nl, nr;
int id;
for(int i = 0 ; i < n; i ++ ){
if(nx.back().se == -1){
g.pop_back();
}
else{
g[nx.back().se] = nx.back().fi;
}
nx.pop_back();
sh = v[i]-x;
l=0,r=cc.size();
while(l < r){
mid = (l + r) / 2;
if(cc[mid] < sh)
l = mid + 1;
else
r = mid;
}
id = l;
if(id == cc.size()){
cc.push_back(sh);
}
else{
cc[id] = sh;
}
l = 0, r = g.size();
while(l + 1 < r){
mid = (l + r) / 2;
if(g[mid] > sh)
l = mid;
else
r = mid;
}
res = max(res, (id+1)+l+(g[l]>sh));
}
cout << res << "\n";
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... |