이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#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;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
ni(n), ni(x);
^
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
glo.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
glo.cpp:35:9: note: in expansion of macro 'ni'
ni(a[i]);
^~
# | 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... |