/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Time Exceeded ≥2578ms ≥1.312 MiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 368.0 KiB
#6 Time Exceeded ≥2585ms ≥1.316 MiB

Code

#include <bits/stdc++.h>


using namespace std;
#define si(a) unordered_map<int, int> freq;
int findMinFreqInteger(const vector<int>& A, int l, int r) {
    si(a);
    int min_freq = (r - l + 1) / 3 + 1;
    int min_integer = -1;

    for (int i = l; i <= r; ++i) {
        freq[A[i]]++;
        if (freq[A[i]] >= min_freq && (min_integer == -1 || A[i] < min_integer)) {
            min_integer = A[i];
        }
    }

    return min_integer;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;

    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;

        int min_integer = findMinFreqInteger(A, l, r);
        cout << min_integer << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1103 The Secret Garden of Numbers
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 16:26:18
Judged At
2024-11-11 02:27:23
Judged By
Score
20
Total Time
≥2585ms
Peak Memory
≥1.316 MiB