44182023-03-27 18:51:09balaaaazsElőzésekcpp14Runtime error 0/100564ms7624 KiB
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n, q;
    std::cin >> n >> q;

    std::vector<int> cars(n);
    for (int i = 0; i < n; i++) {
        std::cin >> cars[i];
    }

    std::vector<int> freq(n+1, 0);
    int most_frequent = 1;
    for (int i = 1; i < n; i++) {
        if (cars[i] < cars[i-1]) {
            std::swap(cars[i], cars[i-1]);
            freq[cars[i]]++;
            if (freq[cars[i]] > freq[most_frequent] || (freq[cars[i]] == freq[most_frequent] && cars[i] < most_frequent)) {
                most_frequent = cars[i];
            }
        }
    }

    for (int i = 0; i < q; i++) {
        int x;
        std::cin >> x;
        std::swap(cars[x-1], cars[x-2]);
        freq[cars[x-1]]++;
        freq[cars[x-2]]++;
        if (freq[cars[x-1]] > freq[most_frequent] || (freq[cars[x-1]] == freq[most_frequent] && cars[x-1] < most_frequent)) {
            most_frequent = cars[x-1];
        }
        if (freq[cars[x-2]] > freq[most_frequent] || (freq[cars[x-2]] == freq[most_frequent] && cars[x-2] < most_frequent)) {
            most_frequent = cars[x-2];
        }
        std::cout << most_frequent << std::endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1792 KiB
subtask20/30
2Runtime error3ms2032 KiB
3Wrong answer3ms2056 KiB
4Wrong answer4ms2340 KiB
5Wrong answer4ms2472 KiB
6Wrong answer8ms2704 KiB
7Runtime error8ms3128 KiB
subtask30/70
8Wrong answer250ms3444 KiB
9Wrong answer201ms4028 KiB
10Wrong answer414ms4624 KiB
11Wrong answer277ms5368 KiB
12Wrong answer351ms5584 KiB
13Wrong answer277ms6188 KiB
14Wrong answer453ms7012 KiB
15Wrong answer456ms7192 KiB
16Wrong answer328ms7096 KiB
17Wrong answer564ms7224 KiB
18Wrong answer476ms7528 KiB
19Wrong answer234ms7624 KiB
20Wrong answer532ms7456 KiB
21Wrong answer522ms7580 KiB