이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ss second
#define ff first
#define ll long long
#define pb push_back
#define mp make_pair
const int N = 2*1e5+11;
int n, k, a[N], f1[N], f2[N], res;
pair <int, int> b[N];
int dp[3][N], c[N], d[N];
int upit1 (int x) {
if (x > n) x = n;
int ret = 0;
for (; x > 0; x-=x&-x) {
ret = max(ret, f1[x]);
}
return ret;
}
int upit2 (int x) {
if (x > n) x = n;
int ret = 0;
for (; x > 0; x-=x&-x) {
ret = max(ret, f2[x]);
}
return ret;
}
void ubaci1 (int x, int kol) {
for (; x <= n; x+=x&-x) {
f1[x] = max(f1[x], kol);
}
}
void ubaci2 (int x, int kol) {
for (; x <= n; x+=x&-x) {
f2[x] = max(f2[x], kol);
}
}
int main() {
cin >> n >> k;
for (int i=0;i<n;i++) {
scanf("%d", &a[i]);
b[i].ff = a[i];
b[i].ss = i;
}
sort (b, b+n);
int br = 1;
c[b[0].ss] = 1;
for (int i=1;i<n;i++) {
if (b[i].ff != b[i-1].ff) br++;
c[b[i].ss] = br;
}
int j = 0;
for (int i=1;i<n;i++) {
if (b[i].ff-k >= b[j].ff) {
while (b[i].ff-k >= b[j].ff) {
d[b[j].ss] = c[b[i-1].ss];
j++;
}
}
}
for (int i=0;i<n;i++) {
int x = c[i];
if (d[i] == 0) d[i] = n;
dp[1][i] = max(upit2(x-1), upit1(d[i]))+1;
ubaci2(x, dp[1][i]);
dp[0][i] = upit1(x-1)+1;
ubaci1(x, dp[0][i]);
res = max(res, dp[0][i]);
res = max(res, dp[1][i]);
}
cout << res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &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... |