Submission #350006

#TimeUsernameProblemLanguageResultExecution timeMemory
350006idk321Dancing Elephants (IOI11_elephants)C++11
26 / 100
9022 ms1644 KiB
#include "elephants.h"

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


const int N = 50000;
int pos[N];
int x[N];
int n;
set<int> val;
int l;

void init(int N, int L, int X[])
{
    n = N;
    l = L;
    for (int i = 0; i < n; i++) x[i] = X[i];
    for (int i = 0; i < n; i++)
    {
        pos[i] = x[i];
    }
}

int update(int ind, int y)
{
    bool added = false;
    int curr = -1;

    for (int i = 0; i < n; i++)
    {
        if (x[i] == pos[ind])
        {
            curr = i;
            x[i] = y;
            pos[ind] = y;
            break;
        }
    }

    bool found = true;
    while (found)
    {
        found = false;
        //cout << curr << " " << x[curr] << endl;
        if (curr != 0 && x[curr - 1] > x[curr])
        {
            swap(x[curr - 1], x[curr]);
            curr--;
            found = true;
        }
        if (curr != n - 1 && x[curr + 1] < x[curr])
        {
            swap(x[curr + 1], x[curr]);
            curr++;
            found = true;
        }
    }


    int last = -1;
    int res = 0;
    for(int i = 0; i < n; i++)
    {
        if (x[i] > last)
        {
            last = x[i] + l;
            res++;
        }
    }

    return res;
}

Compilation message (stderr)

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:29:10: warning: unused variable 'added' [-Wunused-variable]
   29 |     bool added = false;
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...