Submission details
Task:Kyselyt
Sender:jubidubi
Submission time:2025-10-19 19:21:42 +0300
Language:C++ (C++11)
Status:READY
Result:30
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED20
#30
#40
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3, 4details
#2ACCEPTED0.01 s1, 2, 3, 4details
#3ACCEPTED0.01 s1, 3, 4details
#4ACCEPTED0.73 s2, 3, 4details
#5ACCEPTED0.75 s2, 3, 4details
#6ACCEPTED0.68 s2, 3, 4details
#7ACCEPTED0.94 s3, 4details
#8--4details
#9--4details
#10--4details
#11--3, 4details
#12--4details
#13ACCEPTED0.69 s3, 4details
#14--4details
#15--4details
#16--4details

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 202020;
set<pair<int, int>> s[N];

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool check[N];
int numm[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, q;
  cin >> n >> q;

  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  map<int, int> m;
  map<int, int> rm;
  {
    int x = 1;
    for (int i = 0; i < n; ++i) {
      if (m[v[i]] == 0) {
        rm[x] = v[i];
        m[v[i]] = x++;
      }
      v[i] = m[v[i]];
    }
  }

  for (int i = 0; i < n; ++i) s[v[i]].insert({i, s[v[i]].size()});

  while (q--) {
    int a, b;
    cin >> a >> b;

    --a;
    --b;

    vector<int> c;
    for (int i = 0; i < 200; ++i) {
      int j = a + (rng() % (b - a + 1));
      ++numm[v[j]];
      if (!check[v[j]]) {
        c.push_back(v[j]);
        check[v[j]] = 1;
      }
    }

    bool found = 0;
    for (int x : c) {
      check[x] = 0;
      if (numm[x] < 60 || found) {
        numm[x] = 0;
        continue;
      }
      numm[x] = 0;
      auto it = s[x].lower_bound({a, 0});
      auto it2 = s[x].lower_bound({b + 1, 0});
      --it2;
      int num = it2->second - it->second + 1;

      if (num >= (b - a + 1) / 2 + 1) {
        cout << rm[x] << endl;
        found = 1;
      }
    }
    if (!found) cout << "-1" << endl;
  }
}

Test details

Test 1

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 2

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
100 100
2 1 2 2 1 2 2 2 1 2 2 1 1 1 1 ...

correct output
2
1
1
2
1
...

user output
2
1
1
2
1
...

Test 3

Group: 1, 3, 4

Verdict: ACCEPTED

input
100 100
5 19 44 88 14 79 50 44 14 99 7...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 4

Group: 2, 3, 4

Verdict: ACCEPTED

input
100000 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 5

Group: 2, 3, 4

Verdict: ACCEPTED

input
100000 100000
1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 ...

correct output
1
1
2
1
1
...

user output
1
1
2
1
1
...

Test 6

Group: 2, 3, 4

Verdict: ACCEPTED

input
100000 100000
8 2 6 1 10 4 9 7 8 10 4 2 8 2 ...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 7

Group: 3, 4

Verdict: ACCEPTED

input
100000 100000
141307 493258596 365539511 222...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 8

Group: 4

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
(empty)

Test 9

Group: 4

Verdict:

input
200000 200000
1 2 2 2 1 2 2 1 1 1 1 1 1 1 1 ...

correct output
2
2
2
2
2
...

user output
(empty)

Test 10

Group: 4

Verdict:

input
200000 200000
286470749 280175209 741317063 ...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 11

Group: 3, 4

Verdict:

input
100000 100000
613084013 1000000000 411999902...

correct output
-1
-1
-1
-1
1000000000
...

user output
(empty)

Test 12

Group: 4

Verdict:

input
200000 200000
613084013 1000000000 411999902...

correct output
1000000000
1000000000
-1
1000000000
-1
...

user output
(empty)

Test 13

Group: 3, 4

Verdict: ACCEPTED

input
100000 100000
663307073 663307073 663307073 ...

correct output
329574367
965067805
768744535
691214891
21873594
...

user output
329574367
965067805
768744535
691214891
21873594
...

Test 14

Group: 4

Verdict:

input
200000 200000
663307073 663307073 663307073 ...

correct output
107596959
249558965
679275202
760593154
725418770
...

user output
(empty)

Test 15

Group: 4

Verdict:

input
200000 200000
663307073 663307073 663307073 ...

correct output
211070558
49212342
651109313
264549124
651109313
...

user output
(empty)

Test 16

Group: 4

Verdict:

input
200000 200000
2 2 2 1 2 1 1 2 2 1 1 1 1 2 1 ...

correct output
1
2
1
1
1
...

user output
(empty)