/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 1388ms 26.273 MiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 1ms 796.0 KiB
#6 Accepted 1198ms 26.172 MiB
#7 Accepted 1209ms 26.277 MiB
#8 Accepted 929ms 26.344 MiB
#9 Accepted 625ms 26.316 MiB
#10 Accepted 1160ms 26.332 MiB
#11 Accepted 1031ms 26.215 MiB
#12 Accepted 1225ms 26.359 MiB
#13 Accepted 1304ms 26.148 MiB
#14 Accepted 1962ms 26.535 MiB
#15 Accepted 670ms 26.113 MiB
#16 Accepted 1143ms 26.348 MiB

Code

#include<bits/stdc++.h>
#define ll long long
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define testing cout << "testing ";
#define mod 1000000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void do_the_honour() {
    int n; cin >> n;
    int k; cin >> k;

    oset<int>mp[n+1];
    int a[n+1];
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        mp[x].insert(i);
        a[i] = x;
    }

    while (k--) {
        int l, r; cin >> l >> r;
        int sz = r - l + 1;
        int ans = INT_MAX;


        for (int i = 0; i <= 32; i++) {
            int id = l + rand() % sz;

            int cnt = mp[a[id]].order_of_key(r + 1) - mp[a[id]].order_of_key(l);
            if (cnt > (r - l + 1) / 3) ans = min(ans, a[id]);
        }

        if (ans == INT_MAX) cout << -1 << endl;
        else cout << ans << endl;
    }
}

int main() {
    optimize();
    int t = 1;
    for (int z = 1; z <= t; z++) {
        do_the_honour();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1103 The Secret Garden of Numbers
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 17:36:15
Judged At
2024-11-05 17:36:15
Judged By
Score
100
Total Time
1962ms
Peak Memory
26.535 MiB