제출 #485367

#제출 시각아이디문제언어결과실행 시간메모리
485367blue코끼리 (Dancing Elephants) (IOI11_elephants)C++17
26 / 100
9040 ms3040 KiB
#include "elephants.h"
#include <vector>
#include <algorithm>
using namespace std;

const int maxN = 50'000;

int N;
int L;
int* X;
int* I;

void init(int N_, int L_, int X_[])
{
    N = N_;
    L = L_;
    X = new int[N];
    for(int i = 0; i < N; i++) X[i] = X_[i];

    I = new int[N];
    for(int i = 0; i < N; i++) I[i] = i;
}

int update(int i, int y)
{
    int oldX = X[i];
    X[i] = y;

    if(X[i] > oldX)
    {
        for(int j = 0; j+1 < N; j++)
        {
            if(X[I[j]] > X[I[j+1]])
                swap(I[j], I[j+1]);
        }
    }
    else
    {
        for(int j = N-2; j >= 0; j--)
        {
            if(X[I[j]] > X[I[j+1]])
                swap(I[j], I[j+1]);
        }
    }

    int ans = 0;
    int st = -1'000'000'001;

    for(int j = 0; j < N; j++)
    {
        if(X[I[j]] - st > L)
        {
            st = X[I[j]];
            ans++;
        }
    }

    return ans;
}
#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...