/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 5.02 MiB
#2 Accepted 5ms 5.023 MiB
#3 Accepted 945ms 7.086 MiB
#4 Accepted 5ms 5.078 MiB
#5 Accepted 5ms 5.02 MiB
#6 Accepted 1375ms 7.18 MiB
#7 Accepted 912ms 6.973 MiB
#8 Accepted 931ms 7.191 MiB
#9 Accepted 596ms 12.543 MiB
#10 Accepted 954ms 8.242 MiB
#11 Accepted 806ms 12.52 MiB
#12 Accepted 1062ms 7.145 MiB
#13 Accepted 897ms 7.172 MiB
#14 Accepted 1490ms 7.266 MiB
#15 Accepted 656ms 12.461 MiB
#16 Accepted 968ms 8.184 MiB

Code

#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

const int N = 2e5+5;
vector<int> p[N];
int a[N];
void solve() {
    int n,q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        p[a[i]].push_back(i);
    }
    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        int sz = r - l + 1, ans = INT_MAX;
        srand(time(0));
        for(int j = 0; j <= 50; j++) {
            int idx = l + rand() % sz;
            int v = a[idx];
            int cnt = upper_bound(p[v].begin(),p[v].end(),r) - upper_bound(p[v].begin(),p[v].end(),l-1);
            if(cnt > (r - l + 1) / 3) ans = min(ans, v);
        }
        if(ans == INT_MAX) cout << -1 << '\n';
        else cout << ans << '\n';
    }
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    // cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    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:11:06
Judged At
2024-11-05 16:11:07
Judged By
Score
100
Total Time
1490ms
Peak Memory
12.543 MiB