/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 5.133 MiB
#2 Accepted 5ms 5.027 MiB
#3 Accepted 1692ms 7.164 MiB
#4 Accepted 5ms 5.32 MiB
#5 Accepted 6ms 5.062 MiB
#6 Accepted 2030ms 7.262 MiB
#7 Accepted 1715ms 7.137 MiB
#8 Accepted 1673ms 7.379 MiB
#9 Accepted 1260ms 12.57 MiB
#10 Accepted 1566ms 8.242 MiB
#11 Accepted 1871ms 12.586 MiB
#12 Accepted 1600ms 7.242 MiB
#13 Accepted 1654ms 7.254 MiB
#14 Accepted 1990ms 7.445 MiB
#15 Accepted 1180ms 12.559 MiB
#16 Accepted 1403ms 8.246 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-11 02:28:05
Judged By
Score
100
Total Time
2030ms
Peak Memory
12.586 MiB