# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
320943 | phathnv | Global Warming (CEOI18_glo) | C++11 | 96 ms | 7012 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "GlobalWarming"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 2e5 + 1;
const int INF = 1e9 + 10;
struct fenwickTree{
int d[N];
void update(int x, int val){
for(; x < N; x += x & -x)
d[x] = max(d[x], val);
}
int get(int x){
int res = 0;
for(; x > 0; x -= x & -x)
res = max(res, d[x]);
return res;
}
} bit;
int n, x, a[N], l[N], r[N], dp[N], ind[N];
void readInput(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> x;
for(int i = 1; i <= n; i++)
cin >> a[i];
}
void solve(){
dp[0] = -INF;
for(int i = 1; i <= n; i++)
dp[i] = INF;
for(int i = 1; i <= n; i++){
l[i] = lower_bound(dp, dp + n + 1, a[i]) - dp;
dp[l[i]] = min(dp[l[i]], a[i]);
}
dp[0] = INF;
for(int i = 1; i <= n; i++)
dp[i] = -INF;
for(int i = n; i >= 1; i--){
r[i] = lower_bound(dp, dp + n + 1, a[i], greater<int>()) - dp;
dp[r[i]] = max(dp[r[i]], a[i]);
}
for(int i = 1; i <= n; i++)
ind[i] = i;
sort(ind + 1, ind + n + 1, [=](const int &x, const int &y){
return a[x] < a[y];
});
int ptr = 1, res = 0;
for(int i = 1; i <= n; i++){
int pos = ind[i];
while (ptr <= n && a[pos] + x > a[ind[ptr]]){
bit.update(ind[ptr], l[ind[ptr]]);
ptr++;
}
res = max(res, r[pos] + bit.get(pos - 1));
}
cout << res;
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
readInput();
solve();
return 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... |