/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 436.0 KiB
#3 Time Exceeded ≥2599ms ≥2.836 MiB
#4 Accepted 1ms 324.0 KiB
#5 Accepted 1ms 440.0 KiB
#6 Time Exceeded ≥2595ms ≥2.828 MiB

Code

#include <iostream>
#include <vector>
#include <unordered_map>
#include <limits>

using namespace std;

vector<int> pQ(int n, int q, const vector<int>& a, const vector<pair<int, int>>& qry) {
    vector<int> res;

    for (const auto& p : qry) {
        int l = p.first - 1;
        int r = p.second - 1;

        unordered_map<int, int> f;
        for (int i = l; i <= r; ++i) {
            f[a[i]]++;
        }

        int t = (r - l + 1) / 3;
        int mX = numeric_limits<int>::max();

        for (const auto& [num, cnt] : f) {
            if (cnt > t) {
                mX = min(mX, num);
            }
        }

        if (mX == numeric_limits<int>::max()) {
            res.push_back(-1);
        } else {
            res.push_back(mX);
        }
    }

    return res;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<pair<int, int>> qry(q);
    for (int i = 0; i < q; ++i) {
        cin >> qry[i].first >> qry[i].second;
    }

    vector<int> res = pQ(n, q, a, qry);

    for (int r : res) {
        cout << r << 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 14:54:51
Judged At
2024-11-05 14:54:51
Judged By
Score
20
Total Time
≥2599ms
Peak Memory
≥2.836 MiB