이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e9;
struct segtree{
struct node{
int mx;
node(){
mx = 0;
}
node(ll x){
mx = x;
}
node operator+(node a){
node rt;
rt.mx = max(mx, a.mx);
return rt;
}
};
int k;
vector<node> v;
segtree(int n){
k = 1;
while(k < n) k*=2;
k*=2;
v.resize(k, node());
}
void upd(int in, ll x){
in+=k/2;
v[in] = node(x);
in/=2;
while(in > 0){
v[in] = v[2*in]+v[2*in+1];
in/=2;
}
}
ll smx(int l, int r, int nd, int a, int b){
if(b < l || a > r) return 0;
if(a >= l && b <= r) return v[nd].mx;
int c = (a+b)/2;
return max(smx(l, r, 2*nd, a, c), smx(l, r, 2*nd+1, c+1, b));
}
ll smx(int l, int r){
return smx(l, r, 1, 0, k/2-1);
}
};
struct segtree2{
struct node{
int mn;
node(){
mn = 0;
}
node(ll x){
mn = x;
}
node operator+(node a){
node rt;
rt.mn = min(mn, a.mn);
return rt;
}
};
int k;
vector<node> v;
segtree2(int n){
k = 1;
while(k < n) k*=2;
k*=2;
v.resize(k, node());
}
void upd(int in, ll x){
in+=k/2;
v[in] = node(x);
in/=2;
while(in > 0){
v[in] = v[2*in]+v[2*in+1];
in/=2;
}
}
ll smn(int l, int r, int nd, int a, int b){
if(b < l || a > r) return inf;
if(a >= l && b <= r) return v[nd].mn;
int c = (a+b)/2;
return min(smn(l, r, 2*nd, a, c), smn(l, r, 2*nd+1, c+1, b));
}
ll smn(int l, int r){
return smn(l, r, 1, 0, k/2-1);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d; cin >> n >> d;
vector<int> v(n);
for(int &x: v) cin >> x;
vector<int> cmpr;
map<int, int> mp;
cmpr = v;
sort(cmpr.begin(), cmpr.end());
for(int i = 0; i < n; i++) mp[cmpr[i]] = i;
for(int &x: v) x = mp[x];
segtree seg(n);
vector<vector<int>> sth(n);
for(int i = n-1; i >= 0; i--) sth[v[i]].pb(i);
segtree2 seg2(n);
for(int i = 0; i < n; i++) seg2.upd(i, v[i]);
vector<int> lim(n, 0);
set<pair<int, int>> ss;
for(int i = n-1; i >= 0; i--){
if(i+d < n) ss.insert({-v[i+d], i+d});
int x = seg2.smn(i, min(n-1, i+d-1));
while(1){
auto it = ss.lower_bound(make_pair(-x, 0));
if(it == ss.end()) break;
lim[it->sc] = i;
ss.erase(it);
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < sth[i].size(); j++){
int x = seg.smx(lim[sth[i][j]], sth[i][j]-1)+1;
seg.upd(sth[i][j], seg.smx(lim[sth[i][j]], sth[i][j]-1)+1);
}
}
cout << seg.smx(0, n-1) << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:131:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for(int j = 0; j < sth[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
Main.cpp:132:17: warning: unused variable 'x' [-Wunused-variable]
132 | int x = seg.smx(lim[sth[i][j]], sth[i][j]-1)+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... |