제출 #1046568

#제출 시각아이디문제언어결과실행 시간메모리
1046568oscar1fDancing Elephants (IOI11_elephants)C++17
50 / 100
9046 ms10852 KiB
#include<bits/stdc++.h>
#include "elephants.h"
using namespace std;

const int MAX_ELEPH=70*1000+5,INFINI=1000*1000*1000+5;
int nbEleph,taillePhoto;
int posTri[MAX_ELEPH];
int posCour[MAX_ELEPH];

void init(int N, int L, int X[]) {
    nbEleph=N;
    taillePhoto=L;
    for (int i=0;i<nbEleph;i++) {
        posTri[i]=X[i];
        posCour[i]=X[i];
    }
}

int calc() {
    int ans=0,dernDeb=-INFINI;
    for (int i=0;i<nbEleph;i++) {
        if (dernDeb+taillePhoto<posTri[i]) {
            ans++;
            dernDeb=posTri[i];
        }
    }
    return ans;
}

int update(int posModif, int valNouv) {
    int deb=0,fin=nbEleph-1,mid;
    while (deb!=fin) {
        mid=(deb+fin+1)/2;
        if (posTri[mid]<=posCour[posModif]) {
            deb=mid;
        }
        else {
            fin=mid-1;
        }
    }
    int pos=deb;
    posTri[pos]=valNouv;
    posCour[posModif]=valNouv;
    while (pos>0 and posTri[pos]<posTri[pos-1]) {
        swap(posTri[pos-1],posTri[pos]);
        pos--;
    }
    while (pos<nbEleph-1 and posTri[pos]>posTri[pos+1]) {
        swap(posTri[pos],posTri[pos+1]);
        pos++;
    }
    return calc();
}
#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...