| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 707839 | Alihan_8 | Global Warming (CEOI18_glo) | C++17 | 152 ms | 15044 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>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
bool chmax(int &x, int y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, x; cin >> n >> x;
vector <int> p(n), pos;
for ( auto &i: p ){
cin >> i;
pos.pb(i), pos.pb(i+x);
}
sort(all(pos));
pos.resize(unique(all(pos))-pos.begin());
auto f = [&](int x){
return lower_bound(all(pos), x)-pos.begin()+1;
};
vector <int> dp, L(n), R(n);
for ( int i = 0; i < n; i++ ){
auto it = lower_bound(all(dp), p[i])-dp.begin();
L[i] = it+1;
if ( it == (int)dp.size() ) dp.pb(p[i]);
else dp[it] = p[i];
}
dp.clear();
for ( int i = n-1; i >= 0; i-- ){
auto it = lower_bound(all(dp), -p[i])-dp.begin();
R[i] = it+1;
if ( it == (int)dp.size() ) dp.pb(-p[i]);
else dp[it] = -p[i];
}
int sz = (int)pos.size();
vector <int> bit(sz+1);
auto upd = [&](int i, int val){
for (; i <= sz; i += i&-i ) chmax(bit[i], val);
};
auto get = [&](int i){
int Mx = 0;
for (; i > 0; i -= i&-i ) chmax(Mx, bit[i]);
return Mx;
};
int Mx = 0;
for ( int i = 0; i < n; i++ ){
chmax(Mx, get(f(p[i]+x)-1)+R[i]);
upd(f(p[i]), L[i]);
}
cout << Mx;
cout << '\n';
}
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... | ||||
