이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 12;
int n, d, a[maxn], L[maxn * 4], R[maxn * 4], mx[maxn * 4], mn[maxn * 4];
bool ch[maxn * 4];
vector <int> pos;
map <int, int> mp;
void make_tree(int l, int r, int ind){
int mid = (l + r) / 2;
L[ind] = l;
R[ind] = r;
mn[ind] = maxn;
if(l == r)
return;
make_tree(l, mid, ind * 2);
make_tree(mid + 1, r, ind * 2 + 1);
}
void update_tree_mn(int l, int r, int u, int k){
if(r < L[u] || R[u] < l)
return;
if(l <= L[u] && R[u] <= r){
mn[u] = min(mn[u], k);
return;
}
update_tree_mn(l, r, u * 2, k);
update_tree_mn(l, r, u * 2 + 1, k);
mn[u] = max(mn[u * 2], mn[u * 2 + 1]);
}
void push_to(int v){
int u = v / 2;
ch[v] = 1;
mx[v] = mx[u];
}
void update_tree_mx(int l, int r, int u, int k){
if(r < L[u] || R[u] < l)
return;
if(l <= L[u] && R[u] <= r){
mx[u] = max(mx[u], k);
return;
}
if(ch[u]){
push_to(u * 2);
push_to(u * 2 + 1);
}
update_tree_mx(l, r, u * 2, k);
update_tree_mx(l, r, u * 2 + 1, k);
mx[u] = max(mx[u * 2], mx[u * 2 + 1]);
}
void set_tree(int l, int r, int u){
if(r < L[u] || R[u] < l)
return;
if(l <= L[u] && R[u] <= r){
mx[u] = 0;
ch[u] = 1;
return;
}
if(ch[u]){
push_to(u * 2);
push_to(u * 2 + 1);
}
set_tree(l, r, u * 2);
set_tree(l, r, u * 2 + 1);
mx[u] = max(mx[u * 2], mx[u * 2 + 1]);
}
int get_min(int l, int r, int u){
if(r < L[u] || R[u] < l)
return maxn;
if(l <= L[u] && R[u] <= r)
return mn[u];
return min(get_min(l, r, u * 2), get_min(l, r, u * 2 + 1));
}
int get_max(int l, int r, int u){
if(r < L[u] || R[u] < l)
return 0;
if(l <= L[u] && R[u] <= r)
return mx[u];
if(ch[u]){
push_to(u * 2);
push_to(u * 2 + 1);
}
return max(get_max(l, r, u * 2), get_max(l, r, u * 2 + 1));
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n >> d;
for(int i = 1; i <= n; i++){
cin >> a[i];
pos.push_back(a[i]);
}
make_tree(0, n, 1);
sort(pos.begin(), pos.end());
for(int j = 0; j < pos.size(); j++)
mp[pos[j]] = j;
for(int i = 1; i <= n; i++){
a[i] = mp[a[i]];
// cout << a[i] << ' ';
}
// cout << endl;
int ans = 0;
for(int i = n; i >= 1; i--){
int res, loc;
res = get_max(a[i] + 1, n, 1) + 1;
update_tree_mx(a[i], a[i], 1, res);
update_tree_mn(i, i, 1, a[i]);
if(i + d - 1 <= n){
loc = get_min(i, i + d - 1, 1);
// cout << i << "->" << loc << endl;
set_tree(0, loc - 1, 1);
}
ans = max(ans, res);
// cout << i << ' ' << res << endl;
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int j = 0; j < pos.size(); j++)
| ~~^~~~~~~~~~~~
# | 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... |