이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;
int n, m, a[N], dp[N], bit[2*N + 200];
int SIZE;
vector <int> compress;
void upd(int idx, int val){
while (idx > 0)
bit[idx] = max(bit[idx], val),
idx -= idx & -idx;
}
int get(int idx, int ans = 0){
while (idx <= SIZE)
ans = max(bit[idx], ans),
idx += idx & -idx;
return ans;
}
int find(int x){
int l = 0, r = compress.size() - 1, mid, ans = 0;
while (l <= r){
mid = l + r >> 1;
if (compress[mid] >= x)
ans = mid + 1, r = mid - 1;
else
l = mid + 1;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
// #endif
cin >> n >> m;
compress.push_back(0); // current standing
for (int i = 1; i <= n; i ++){
cin >> a[i];
compress.push_back(a[i]);
compress.push_back(max(0, a[i] - m));
}
// cordinate compression
sort(compress.begin(), compress.end());
compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
SIZE = compress.size() + 100;
// -> erase duplicate elements
// PROCESS: key idea -> finding longest possible path = L -> ans = n - L
upd(find(0), 1);
for (int i = 1; i <= n; i ++){
int cur = find(max(0, a[i] - m));
ll tmp = get(cur) + 1;
if (tmp == 1) continue;
upd(find(a[i]), tmp);
}
cout << n - get(1) + 1;
return 0;
}
/** /\_/\
(= ._.)
/ >0 \>1
________________________
/ Brainstorming section /
/=======================/
---
===
===
**/
// Before submit: spot the visible bug by reading the code.
컴파일 시 표준 에러 (stderr) 메시지
triusis.cpp: In function 'int find(int)':
triusis.cpp:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | 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... |