| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 104953 | eriksuenderhauf | Global Warming (CEOI18_glo) | C++11 | 91 ms | 4800 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.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
int a[MAXN], dp[MAXN], len[MAXN];
int main() {
int n, x;
ni(n), ni(x);
int ans = 0;
for (int i = 1; i <= n; i++) {
ni(a[i]);
int lo = 0, hi = ans, nx = 0, nx2 = 0;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (a[dp[m]] < a[i])
lo = m + 1, nx = m;
else
hi = m - 1;
}
lo = 0, hi = ans;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (a[dp[m]] < a[i] + x)
lo = m + 1, nx2 = m;
else
hi = m - 1;
}
ans = max(ans, nx + 1);
len[i] = nx2;
if (dp[nx + 1] == 0)
dp[nx + 1] = i;
if (a[dp[nx + 1]] > a[i])
dp[nx + 1] = i;
}
a[n + 1] = INF;
fill(dp, dp + MAXN, n + 1);
int ret = 0;
ans = 0;
for (int i = n; i > 0; i--) {
int lo = 0, hi = ans, nx = 0;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (a[dp[m]] > a[i])
lo = m + 1, nx = m;
else
hi = m - 1;
}
ans = max(ans, nx + 1);
if (dp[nx + 1] == n + 1)
dp[nx + 1] = i;
if (a[dp[nx + 1]] < a[i])
dp[nx + 1] = i;
ret = max(ret, nx + 1 + len[i]);
}
printf("%d\n", ret);
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... | ||||
