# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961586 | 0npata | Crossing (JOI21_crossing) | C++17 | 0 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define snd second
#define fst first
#define pb push_back
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, d;
cin >> n >> d;
vec<int> a(n);
for(int i = 0; i<n; i++) {
cin >> a[i];
}
map<int, int> bst;
multiset<int> lstd;
for(int i = 0; i<n; i++) {
if(lstd.size() == d) {
int mn = *lstd.begin();
while(bst.begin() != bst.end()) {
if((*bst.begin()).fst < mn) {
bst.erase(bst.begin());
}
else {
break;
}
}
}
auto nxt = bst.lower_bound(a[i]);
int res;
if(nxt == bst.begin()) {
res = 1;
}
else {
auto prev = nxt;
prev--;
res = (*prev).snd + 1;
}
vec<int> te(0);
while(nxt != bst.end()) {
if((*nxt).snd <= res) {
te.pb((*nxt).fst);
}
nxt++;
}
for(int e : te) {
bst.erase(e);
}
if(bst[a[i]] < res) {
bst[a[i]] = res;
}
lstd.insert(a[i]);
if(i-d >= 0) {
lstd.erase(lstd.find(a[i-d]));
}
}
int ans = (*bst.rbegin()).second;
cout << ans << '\n';
}
Compilation message (stderr)
# | 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... |