# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1057157 | vjudge1 | Global Warming (CEOI18_glo) | C++17 | 91 ms | 17392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 1e6 + 5;
#define ALL(a) (a).begin(), (a).end()
#define LB(a, x) (lower_bound(ALL(a), x) - (a).begin() + 1)
struct fenwick0 {
int tree[MAXN];
void update(int x, int v) {
for(; x < MAXN; x += (x & -x))
tree[x] = max(tree[x], v);
}
int get(int x) {
int res = 0;
for(; x; x -= (x & -x))
res = max(res, tree[x]);
return res;
}
} bit0;
struct fenwick1 {
int tree[MAXN];
void update(int x, int v) {
for(; x; x -= (x & -x))
tree[x] = max(tree[x], v);
}
int get(int x) {
int res = 0;
for(; x < MAXN; x += (x & -x))
res = max(res, tree[x]);
return res;
}
} bit1;
int N, K;
int a[MAXN];
int b[MAXN];
int dp[MAXN];
void compress() {
vector<int> temp;
for(int i = 1; i <= N; i++) {
temp.emplace_back(a[i]);
temp.emplace_back(b[i]);
}
sort(ALL(temp));
temp.resize(unique(ALL(temp)) - temp.begin());
for(int i = 1; i <= N; i++) {
a[i] = LB(temp, a[i]);
b[i] = LB(temp, b[i]);
}
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) b[i] = a[i] + K;
compress();
for(int i = 1; i <= N; i++) {
dp[i] = bit0.get(a[i] - 1) + 1;
bit0.update(a[i], dp[i]);
}
int ans = dp[N];
for(int i = N; i >= 1; i--) {
ans = max(ans, dp[i] + bit1.get(a[i] + 1));
int cur = bit1.get(b[i] + 1);
bit1.update(b[i], cur + 1);
}
cout << ans;
return (0 ^ 0);
}
컴파일 시 표준 에러 (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... |