이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int s, e, m;
int v = 0;
node *l = nullptr, *r = nullptr;
node(int _s, int _e){
s = _s, e = _e, m = (s+e)/2;
}
void deletefkfkfk(){
if (l != nullptr) l->deletefkfkfk(), delete l;
if (r != nullptr) r->deletefkfkfk(), delete r;
}
void make_l(){
if (l == nullptr) l = new node(s, m);
}
void make_r(){
if (r == nullptr) r = new node(m+1, e);
}
void update(int x, int y){
if (s == e) {v = max(v, y); return;}
if (x <= m) make_l(), l->update(x, y), v = max(v, l->v);
else make_r(), r->update(x, y), v = max(v, r->v);
}
int query(int x, int y){
//cout << s << ' ' << e << '\n';
if (x <= s && e <= y) return v;
if (y <= m) {
if (l == nullptr) return 0;
return l->query(x, y);
}
else if (x > m) {
if (r == nullptr) return 0;
return r->query(x, y);
}
else {
if (l == nullptr && r == nullptr) return 0;
if (l == nullptr) return r->query(m+1, y);
if (r == nullptr) return l->query(x, m);
return max(l->query(x, m), r->query(m+1, y));
}
}
};
main(){
int n, bruh; cin >> n; cin >> bruh;
int arr[n];
for (int x = 0; x < n; x++) cin >> arr[x];
node st2(0, 2000000000), st3(0, 2000000000);
int plis[n];
int slis[n];
for (int x = n-1; x > -1; x--){
slis[x] = st2.query(arr[x]+1, 2000000000)+1;
st2.update(arr[x], slis[x]);
}
int ans = 0;
for (int x = 0; x < n; x++){
plis[x] = st3.query(0, arr[x]-1)+1;
ans = max(ans, st3.query(0, arr[x] + bruh - 1) + slis[x]);
st3.update(arr[x], plis[x]);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main(){
| ^~~~
# | 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... |