/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Time Exceeded ≥2583ms ≥2.828 MiB
#4 Accepted 1ms 516.0 KiB
#5 Accepted 1ms 528.0 KiB
#6 Time Exceeded ≥2573ms ≥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-11 02:32:09
Judged By
Score
20
Total Time
≥2583ms
Peak Memory
≥2.828 MiB