이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n, x, mx, a[200005];
vector<int> t,L,R;
int addNode(int val=0)
{
t.PB(val);
L.PB(-1);
R.PB(-1);
return ((int)t.size() - 1);
}
void build()
{
t.clear();
addNode();
addNode();
}
void add(int v, int l, int r, int pos,int val)
{
if (l == r)
{
t[v] = max(t[v],val);
return;
}
int m = (l + r) >> 1;
if (L[v] == -1)
L[v] = addNode();
if (R[v] == -1)
R[v] = addNode();
if (pos <= m)
add(L[v], l, m, pos, val);
else
add(R[v], m + 1, r, pos, val);
t[v] = max(t[L[v]], t[R[v]]);
}
int get(int v,int l,int r,int pos)
{
if (r == pos)
return t[v];
int m = (l + r) >> 1;
if (L[v] == -1)
L[v] = addNode();
if (R[v] == -1)
R[v] = addNode();
if (pos <= m)
return get(L[v], l, m, pos);
else
return max(t[L[v]], get(R[v], m + 1, r, pos));
}
int main()
{
cin >> n >> x;
for (int i = 1; i <= n; i++)
{
scanf("%d", a + i);
mx = max(mx, a[i]);
}
mx += x+10;
build();
for (int i = 1; i <= n; i++)
{
add(1, 1, mx, a[i] + x, get(1, 1, mx, a[i] + x - 1) + 1);
add(1, 1, mx, a[i] + x, get(0, 1, mx, a[i] + x - 1) + 1);
add(0, 1, mx, a[i], get(0, 1, mx, a[i] - 1) + 1);
}
cout << get(1, 1, mx, mx) << endl;
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:86: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... |