답안 #785906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785906 2023-07-17T18:39:11 Z MinaRagy06 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,O3")
using namespace std;
typedef int64_t ll;

int n, l;
int a[150'005][2];
void init(int N, int L, int X[]) {
    n = N, l = L;
    pair<int, int> v[n];
    for (int i = 0; i < n; i++) {
        v[i] = {X[i], i};
    }
    sort(v, v + n);
    for (int i = 0; i < n; i++) {
        a[i][0] = v[i].first;
        a[i][1] = v[i].second;
    }
}
int update(int x, int y) {
    int pos = -1;
    for (int i = 0; i < n; i++) {
        if (a[i][1] == x) {
            pos = i;
            break;
        }
    }
    if (a[pos][0] < y) {
        a[pos][0] = y;
        for (int i = pos; i + 1 < n && a[i][0] > a[i + 1][0]; i++) {
            swap(a[i][0], a[i + 1][0]);
            swap(a[i][1], a[i + 1][1]);
        }
    } else {
        a[pos][0] = y;
        for (int i = pos; i - 1 >= 0 && a[i][0] < a[i - 1][0]; i--) {
            swap(a[i][0], a[i - 1][0]);
            swap(a[i][1], a[i - 1][1]);
        }
    }
    int prv = a[0][0], cnt = 0;
    for (int i = 1; i < n; i++) {
        if (a[i][0] - prv > l) {
            cnt++;
            prv = a[i][0];
        }
    }
    return cnt + 1;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int N, L;
    cin >> N >> L;
    int X[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    init(N, L, X);
    int Q;
    cin >> Q;
    while (Q--) {
        int I, Y;
        cin >> I >> Y;
        cout << update(I, Y) << '\n';
    }
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccQIfL3D.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccaaqmVH.o:elephants.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status