이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int maxv = 2e9+10;
struct Node
{
int v;
Node *l, *r;
Node()
{
v = 0;
l = r = NULL;
}
};
int n, x;
int num[maxn];
int pref[maxn], suf[maxn];
int get(Node *t) {return (t ? t->v : 0);}
void upd(Node *node, int l, int r, int pos, int v)
{
if (l == r)
{
node->v = max(v, node->v);
return;
}
int mid = (l+r)>>1;
if (pos <= mid)
{
if (!node->l) node->l = new Node();
upd(node->l, l, mid, pos, v);
}
else
{
if (!node->r) node->r = new Node();
upd(node->r, mid+1, r, pos, v);
}
node->v = max(get(node->l), get(node->r));
}
int query(Node *node, int l, int r, int a, int b)
{
if (!node || l > b || r < a) return 0;
if (l >= a && r <= b) return node->v;
int mid = (l+r)>>1;
int p1 = query(node->l, l, mid, a, b);
int p2 = query(node->r, mid+1, r, a, b);
return max(p1, p2);
}
int main(void)
{
scanf("%d %d", &n, &x);
Node *t = new Node();
for (int i = 1; i <= n; i++)
scanf("%d", &num[i]);
for (int i = 1; i <= n; i++)
{
int val = 0;
if (num[i] > 1)
val = query(t, 1, maxv-1, 1, num[i]-1);
pref[i] = val+1;
upd(t, 1, maxv-1, num[i], pref[i]);
}
t = new Node();
for (int i = n; i >= 1; i--)
{
int val = query(t, 1, maxv-1, num[i]+1, maxv-1);
suf[i] = val+1;
upd(t, 1, maxv-1, num[i], suf[i]);
}
int ans = 0;
t = new Node();
for (int i = 1; i <= n; i++)
{
int val = 0;
if (num[i]+x > 1) val = query(t, 1, maxv-1, 1, num[i]+x-1);
ans = max(ans, suf[i]+val);
upd(t, 1, maxv-1, num[i], pref[i]);
}
t = new Node();
for (int i = n; i >= 1; i--)
{
int val = query(t, 1, maxv-1, max(1, num[i]-x+1), maxv-1);
ans = max(ans, pref[i]+val);
upd(t, 1, maxv-1, num[i], suf[i]);
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &x);
~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &num[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... |