# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1249155 | redacode | Dancing Elephants (IOI11_elephants) | C++20 | 0 ms | 0 KiB |
#include "elephants.h"
#include "bits/stdc++.h"
using namespace std;
int n;
int l;
bool cmp(pair<int, int>& a,
pair<int, int>& b)
{
return a.second < b.second;
}
set<pair<int, int> > A;
/*
void sort_map(map<int, int>& M)
{
A.clear();
for (auto& it : M) {
A.push_back(it);
}
sort(A.begin(), A.end(), cmp);
} */
map<int,int> pos;
void init(int N, int L, int X[])
{
n = N;
l =L;
for(int i=0;i<n;i++){
pos[i]=X[i];
A.insert({i,X[i]});
}
}
int update(int i, int y)
{
if(n==1){
return 1;
}
A.erase({i,pos[i]});
pos[i]=y;
A.insert({i,pos[i]});
//sort_map(pos);
int cnt =0;
int start = *A.begin();
for(auto&: it){
if(it.second-start>l){
start = it.second;
cnt++;
}
if(i==n-1) cnt++;
}
if(cnt==0)cnt++;
return cnt;
}