| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1284783 | celes | Global Warming (CEOI18_glo) | C++20 | 85 ms | 5452 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 = 3e5 + 5;
int n, x;
int a[N], c[N], val[N];
vector<int> b;
int fenpre[N], fensuf[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".ans", "w", stdout);
}
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.ans", "w", stdout);
}
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c[i] = a[i];
b.pb(a[i]);
}
b.pb(0);
Unique(b);
for (int i = 1; i <= n; i++)
a[i] = lower_bound(all(b), a[i]) - b.begin();
for (int i = 1; i <= n; i++) {
ll p = get(fenpre, a[i] - 1) + 1;
val[i] = p;
update(fenpre, a[i], p);
}
int res = 0;
for (int i = n; i >= 1; i--) {
int p = get(fensuf, N - 3 - a[i] - 1) + 1;
int low = max(0, c[i] - x);
int idx = upper_bound(all(b), low) - b.begin() - 1;
res = max(res, val[i] + get(fensuf, N - 3 - idx - 1));
update(fensuf, N - 3 - a[i], p);
}
cout<<res;
cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n";
}
컴파일 시 표준 에러 (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... | ||||
