이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 10;
const int INF = 1e9 + 7;
struct segtree{
int st[MX << 2], lz[MX << 2];
void build(int id, int l, int r){
if(l == r){
st[id] = -INF;
lz[id] = 0;
}else{
int mid = l + r >> 1;
build(id << 1, l, mid);
build(id << 1|1, mid + 1, r);
st[id] = max(st[id << 1], st[id << 1|1]);
}
}
void prop(int id, int l, int r){
if(lz[id] == 0) return;
st[id] += lz[id];
if(l != r){
lz[id << 1] += lz[id];
lz[id << 1|1] += lz[id];
}
lz[id] = 0;
}
void upd_pos(int id, int l, int r, int p, int v){
prop(id, l, r);
if(r < p || l > p) return;
if(l == p && p == r){
st[id] = v;
}else{
int mid = l + r >> 1;
upd_pos(id << 1, l, mid, p, v);
upd_pos(id << 1|1, mid + 1, r, p, v);
st[id] = max(st[id << 1], st[id << 1|1]);
}
}
void upd(int id, int l, int r, int from, int to, int v){
prop(id, l, r);
if(r < from || l > to) return;
if(from <= l && r <= to){
lz[id] += v;
prop(id, l, r);
}else{
int mid = l + r >> 1;
upd(id << 1, l, mid, from, to, v);
upd(id << 1|1, mid + 1, r, from, to, v);
st[id] = max(st[id << 1], st[id << 1|1]);
}
}
int que(int id, int l, int r, int from, int to){
prop(id, l, r);
if(r < from || l > to) return -INF;
if(from <= l && r <= to){
return st[id];
}else{
int mid = l + r >> 1;
return max(
que(id << 1, l, mid, from, to),
que(id << 1|1, mid + 1, r, from, to)
);
}
}
} S, T;
vector<int> cc;
int N, X, arr[MX], pref[MX], suff[MX];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> X;
for(int i = 0; i < N; i++){
cin >> arr[i];
cc.push_back(arr[i]);
}
cc.push_back(0);
sort(cc.begin(), cc.end());
cc.resize(unique(cc.begin(), cc.end()) - cc.begin());
S.build(1, 0, N);
S.upd_pos(1, 0, N, 0, 0);
for(int i = 0; i < N; i++) arr[i] = lower_bound(cc.begin(), cc.end(), arr[i]) - cc.begin();
for(int i = 0; i < N; i++){
pref[i] = S.que(1, 0, N, 0, arr[i] - 1) + 1;
S.upd_pos(1, 0, N, arr[i], pref[i]);
}
T.build(1, 1, N + 1);
T.upd_pos(1, 1, N + 1, N + 1, 0);
for(int i = N - 1; i >= 0; i--){
suff[i] = T.que(1, 1, N + 1, arr[i] + 1, N + 1) + 1;
T.upd_pos(1, 1, N + 1, arr[i], suff[i]);
}
int ans = suff[0];
for(int i = 0; i < N; i++) ans = max(ans, pref[i] + suff[i + 1]);
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In member function 'void segtree::build(int, int, int)':
glo.cpp:15:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
15 | int mid = l + r >> 1;
| ~~^~~
glo.cpp: In member function 'void segtree::upd_pos(int, int, int, int, int)':
glo.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mid = l + r >> 1;
| ~~^~~
glo.cpp: In member function 'void segtree::upd(int, int, int, int, int, int)':
glo.cpp:52:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int mid = l + r >> 1;
| ~~^~~
glo.cpp: In member function 'int segtree::que(int, int, int, int, int)':
glo.cpp:65:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | int mid = l + r >> 1;
| ~~^~~
# | 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... |