이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 1e9 + 7
using namespace std;
int n, X, a[200001], b[200001], res1[200001], res2[200001], L[200001];
map<int,int> mp;
vector<int> t;
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr)/2;
if (pos <= tm) update(2*v,tl,tm,pos,val);
else update(2*v+1,tm+1,tr,pos,val);
t[v] = max(t[2*v],t[2*v+1]);
}
int getMax(int v, int tl, int tr, int l, int r) {
if (l > r) return -INF;
if (tl > r || tr < l) return -INF;
if (tl >= l && tr <= r) return t[v];
int tm = (tl + tr)/2;
return max(getMax(2*v,tl,tm,l,r),getMax(2*v+1,tm+1,tr,l,r));
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> X;
vector<int> tmp;
for (int i = 1; i <= n; i++) {
cin >> a[i];
tmp.push_back(a[i]);
tmp.push_back(a[i] - X);
}
sort(tmp.begin(),tmp.end());
int cnt = 1;
mp[tmp[0]] = 1;
for (int i = 1; i < tmp.size(); i++) {
if (tmp[i] != tmp[i-1]) cnt++;
mp[tmp[i]] = cnt;
}
t.assign(4*cnt + 1,0);
int lis = 0;
for (int i = n; i >= 1; i--) {
int pos = upper_bound(L,L + lis, -a[i]) - L;
L[pos] = -a[i];
res1[i] = pos + 1;
update(1,1,n,mp[a[i]],res1[i]);
lis = max(lis, pos + 1);
}
for (int i = 1; i <= n; i++) a[i] -= X;
lis = 0;
for (int i = 1; i <= n; i++) {
int pos = upper_bound(L,L + lis, a[i]) - L;
L[pos] = a[i];
res2[i] = pos + 1;
lis = max(lis, pos + 1);
}
int res = 0;
for (int i = 1; i <= n; i++) {
int cur = max(0,getMax(1,1,n, mp[a[i]] + 1, cnt));
update(1,1,n,mp[a[i] + X], -INF);
res = max(res,res2[i] + cur);
}
cout << res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 1; i < tmp.size(); 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... |