이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
int s, e, m, mini, tail, lazytail;
bool removed;
node *l, *r;
node(int S, int E){
s = S;
e = E;
m = (s+e)/2;
if(s == 0){
mini = -1;
}
else{
mini = INT_MAX;
}
tail = -1;
removed = 0;
lazytail = 0;
if(s != e){
l = new node(s, m);
r = new node(m+1, e);
}
}
void propagate(){
if(removed){
removed = 0;
mini = INT_MAX;
tail = INT_MIN;
if(s != e){
l->removed = 1;
r->removed = 1;
}
}
if(lazytail){
tail += lazytail;
if(s != e){
l->lazytail += lazytail;
r->lazytail += lazytail;
}
lazytail = 0;
}
}
void addtail(int S){
propagate();
if(e < S) return;
if(s >= S){
lazytail++;
return;
}
l->addtail(S);
r->addtail(S);
}
void remove(int E){
propagate();
if(s > E) return;
if(s && e <= E){
removed = 1;
propagate();
return;
}
if(s != e){
l->remove(E);
r->remove(E);
mini = min(l->mini, r->mini);
}
//last case: s==e==0 do nothing
}
void updatemini(int idx, int val, int newtail){
propagate();
if(s > idx || e < idx) return;
if(s == idx && e == idx){
mini = val;
tail = newtail;
return;
}
l->updatemini(idx, val, newtail);
r->updatemini(idx, val, newtail);
mini = min(l->mini, r->mini);
}
pair<int, int> walk(int val){
propagate();
if(s == e) return {s, tail};
if(r->mini < val) return r->walk(val);
return l->walk(val);
}
//range update tail from x-end, tail += 1
//range update mini from 1-x, set mini = INT_MAX
//range update tail from 1-x, set tail = INT_MIN
//point update mini at x, set mini = val
//binary search for position of min val
} *root;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d, x;
pair<int, int> data;
cin>>n>>d;
root = new node(0, n);
vector<int> a(n);
for(int i=0; i<n; i++){
cin>>a[i];
}
for(int i=0; i<n; i++){
x = a[i];
data = root->walk(x); //{idx, tail}
if(data.first && i - data.second > d){
root->updatemini(data.first, INT_MAX, INT_MIN);
i--;
}
else{
root->updatemini(data.first + 1, x, i-1);
root->addtail(data.first + 1);
}
}
data = root->walk(INT_MAX-1);
cout<<data.first;
return 0;
}
# | 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... |