| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1284795 | celes | Global Warming (CEOI18_glo) | C++20 | 83 ms | 5264 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end())
const int N = 2e5 + 5;
int n, x;
int a[N], f[N], dp[N];
int ans;
vector<int> pos;
int pre[N], suf[N];
void update(int bit[], int u, int val) {
while (u < N) {
bit[u] = max(bit[u], val);
u += u & -u;
}
}
int get(int bit[], int u) {
int res = 0;
while (u) {
res = max(res, bit[u]);
u -= u & -u;
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "bseq"
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
cin>>n>>x;
for (int i = 1; i <= n; i++) {
cin>>a[i];
f[i] = a[i];
pos.push_back(a[i]);
}
pos.push_back(INT_MIN); Unique(pos);
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(all(pos), a[i]) - pos.begin();
dp[i] = get(pre, a[i] - 1) + 1;
update(pre, a[i], dp[i]);
}
for (int i = n; i >= 1; i--) {
int j = upper_bound(all(pos), max(0, f[i] - x)) - pos.begin() - 1;
ans = max(ans, dp[i] + get(suf, N - 4 - j));
update(suf, N - 3 - a[i], get(suf, N - 4 - a[i]) + 1);
}
cout<<ans;
cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\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... | ||||
