제출 #1354039

#제출 시각아이디문제언어결과실행 시간메모리
1354039toast12코끼리 (Dancing Elephants) (IOI11_elephants)C++20
26 / 100
9090 ms1320 KiB
// N^2 solution
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

int n, l;
vector<int> a;
vector<int> idxs;
vector<int> dp;

void calc() {
    for (int i = n-1; i >= 0; i--) {
        dp[i] = 1;
        auto it = upper_bound(a.begin(), a.end(), a[i]+l);
        if (it != a.end()) {
            int idx = it-a.begin();
            dp[i] = 1+dp[idx];
        }
    }
}

void init(int N, int L, int X[]) {
    n = N;
    l = L;
    idxs.resize(n);
    for (int i = 0; i < n; i++) {
        a.push_back(X[i]);
        idxs[i] = i;
    }
    dp.resize(n);
    calc();
}

int update(int i, int y) {
    for (int j = 0; j < n; j++) {
        if (idxs[j] == i) {
            idxs.erase(idxs.begin()+j);
            a.erase(a.begin()+j);
            break;
        }
    }
    vector<int> p, q;
    bool added = false;
    for (int j = 0; j < n-1; j++) {
        if (!added && a[j] > y) {
            p.push_back(y);
            q.push_back(i);
            added = true;
        }
        p.push_back(a[j]);
        q.push_back(idxs[j]);
    }
    if (!added) {
        p.push_back(y);
        q.push_back(i);
    }
    swap(a, p);
    swap(q, idxs);
    calc();
    return dp[0];
}
#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...