이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
const int MX = 2e5 + 5;
int n, x, t[MX];
vector<int> lis[2];
int find(int id, int l, int r, int val) {
if(l == r) {
if(lis[id][l] < val) return l;
else return l - 1;
}
int mid = (l + r) / 2;
if(lis[id][mid] < val) return find(id, mid + 1, r, val);
else return find(id, l, mid, val);
}
void show() {
for(int id = 0; id < 2; id++) {
for(int i = 0; i < (int)lis[id].size(); i++) cout << lis[id][i] << " ";
cout << "\n";
}
cout << "---------------\n";
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> x;
for(int i = 0; i < n; i++) {
cin >> t[i];
if(!i) {
lis[0].push_back(t[0]);
lis[1].push_back(t[0]);
continue;
}
int a = find(0, 0, (int)lis[0].size() - 1, t[i]);
int b = find(1, 0, (int)lis[1].size() - 1, t[i]);
int c = find(0, 0, (int)lis[0].size() - 1, t[i] + x);
for(int i = max(a, b); i < c ; i++) {
lis[1][i + 1] = min(lis[1][i + 1], t[i]);
}
if(c == lis[1].size() - 1) lis[1].push_back(t[i]);
else lis[1][c + 1] = min(lis[1][c + 1], t[i]);
if(a == (int)lis[0].size() - 1) lis[0].push_back(t[i]);
else lis[0][a + 1] = t[i];
if(b == (int)lis[1].size() - 1) lis[1].push_back(t[i]);
else lis[1][b + 1] = t[i];
//show();
}
cout << (int)lis[1].size();
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:60:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if(c == lis[1].size() - 1) lis[1].push_back(t[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... |