Submission #248567

#TimeUsernameProblemLanguageResultExecution timeMemory
248567A02Dancing Elephants (IOI11_elephants)C++14
Compilation error
0 ms0 KiB
#include "elephants.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>

using namespace std;

int n;
long long l;
int previous_cameras = n;
vector<long long> elephant_positions;
set<long long> sorted_elephant_set;

void init(int N, int L, int X[])
{
    n = N;
    l = L;

    for (int i = 0; i < N; i++){
        elephant_positions.push_back(X[i]);
        sorted_elephant_set.insert(X[i]);
    }

}

int update(int i, int y)
{

    sorted_elephant_set.erase(elephant_positions[i]);
    sorted_elephant_set.insert(y);
    elephant_positions[i] = y;

    long long current_start = -2 * l;
    long long current_cameras = 0;

    if (previous_cameras > sqrt(n)){
        for (set<long long>::iterator it = sorted_elephant_set.upper_bound(current_start); it != sorted_elephant_set.end(); it = sorted_elephant_set.upper_bound(current_start)){

            current_start = *(it) + l;
            current_cameras++;

        }
    } else {

        for (set<long long>::iterator it = sorted_elephant_set.upper_bound(current_start); it != sorted_elephant_set.end(); it++){

            if ((*it) > current_start){
                current_start = *(it) + l;
                current_cameras++;
            }

        }
    }

    previous_cameras = current_cameras;

    return current_cameras;

}

Compilation message (stderr)

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:39:28: error: 'sqrt' was not declared in this scope
     if (previous_cameras > sqrt(n)){
                            ^~~~
elephants.cpp:39:28: note: suggested alternative: 'qsort'
     if (previous_cameras > sqrt(n)){
                            ^~~~
                            qsort