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 "elephants.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n,l;
pbds_set<int> elephants;
vector<int> elpos;
vector<int> dp;
void init(int N, int L, int X[]) {
n=N;l=L;
elpos.resize(n);
dp.resize(n);
for (int i = 0; i<n; i++){
elpos[i]=X[i];
elephants.insert(X[i]);
}
}
int update(int i, int y) {
if (l==0){
return n;
}
int minchanged = min(elpos[i],y);
//cout<<minchanged<<'\n';
elephants.erase(elpos[i]);
elpos[i]=y;
elephants.insert(y);
auto it = elephants.lower_bound(minchanged-10*l);
if (it!=elephants.begin()){
it--;
}
if (it!=elephants.begin()){
it--;
}
//auto it = elephants.begin();
int ptr = int(elephants.order_of_key(*it));
//cout<<ptr<<'\n';
while (it!=elephants.end()){
int e = *it;
//cout<<e<<'\n';
int lastel = elephants.order_of_key(e-l);
if (lastel==0){
dp[ptr]=1;
} else {
dp[ptr]=dp[lastel-1]+1;
}
ptr++;
it++;
}
return dp[n-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... |