Submission details
Task:Kyselyt
Sender:Lieska
Submission time:2025-10-18 13:01:51 +0300
Language:C++ (C++20)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
#40
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4details
#2ACCEPTED0.00 s1, 2, 3, 4details
#3ACCEPTED0.00 s1, 3, 4details
#4--2, 3, 4details
#5--2, 3, 4details
#6--2, 3, 4details
#7ACCEPTED0.35 s3, 4details
#8--4details
#9--4details
#10ACCEPTED0.77 s4details
#11--3, 4details
#12--4details
#130.35 s3, 4details
#140.76 s4details
#15--4details
#16--4details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:32:24: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if (s.count(u) >= sq) s1.insert(u);
      |                        ^

Code

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

#define f first
#define s second

int t[202020][500];
int x[202020];
int rev_map1[500];
map<int, int> m;
vector<int> r[1000];
int rev_map[1000];
int qa[202020], qb[202020];
map<pair<int, int>, int> ans;
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int sq = 1;
    while (sq*sq < n) sq++;
    multiset<int> s;
    for (int i=1; i<=n; ++i){
        cin >> x[i];
        s.insert(x[i]);
    }
    set<int> s1;
    for (auto u:s){
        if (s.count(u) >= sq) s1.insert(u);
    }
    int c =1;
    for (auto u:s1){
        m[u] = c;
        rev_map1[c]= u;
        c++;
    }
    for (int i=1; i<=n; ++i){
        int d = m[x[i]];
        for (int j=1; j<=c; ++j){
            t[i][j] = t[i-1][j];
            if (d == j) t[i][j]++;
        }
    }
    vector<pair<int, int>> v;
    for (int i=1; i<=q; ++i){
        cin >> qa[i] >> qb[i];
        if (qb[i] - qa[i] <= sq) v.push_back({qb[i], qa[i]});
    }
    sort(v.begin(), v.end());
    int ind_v = 0;
    for (int i=1; i<=sq; ++i){
        map<int, int> m1;
        int ind_s = (i-1)*sq + 1;
        int ind_e = min((i+1)*sq, n);
        int d = 1;
        
        for (int j=ind_s; j<=ind_e; ++j){
            int x1 = x[j];
            if (!m1[x1]){
                m1[x1] = d;
                rev_map[d] = x1;
                d++;
            }
            int ma = m1[x1];
            r[ma].push_back(j);
        }
        while (v[ind_v].f <= ind_e){
            bool found = false;
            for (int j=1; j<d; ++j){
                int s = 0;
                for (auto u:r[j]){
                    if (u >= v[ind_v].s && u <= v[ind_v].f) s++;
                }
                //cout << i << " " << ind_v << " " << s << " " << j << "  " << v[ind_v].f << " " << v[ind_v].s << "\n";
                if (2*s > v[ind_v].f - v[ind_v].s +1){
                    ans[{v[ind_v].s, v[ind_v].f}] = rev_map[j];
                    found = true;
                    //cout << "here " << ans[{v[ind_v].s, v[ind_v].f}] << "\n";
                    break;
                }
            }
            if (found == false) ans[{v[ind_v].f, v[ind_v].s}] = -1;
            ind_v++;
        }
        for (int j=1; j<=d; ++j) {
            r[j].clear();
            rev_map[j] = 0;
        }
    }
    
    for (int i=1; i<=q; ++i){
        int a = qa[i], b = qb[i];
        if (b-a <= sq){
            if (ans[{a,b}]) cout << ans[{a, b}] << "\n";
            else cout << "-1\n";
        }
        else {
            bool found = false;
            for (int j=1; j<=c; ++j){
                if ((t[b][j] - t[a-1][j])*2 > b-a+1 ){
                    cout << rev_map1[j] << "\n";
                    found = true;
                    break;
                }
            }
            if (found == false) cout << "-1\n";
        }
    }
}
 
 
 

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:

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
(empty)

Test 5

Group: 2, 3, 4

Verdict:

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
(empty)

Test 6

Group: 2, 3, 4

Verdict:

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
(empty)

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: ACCEPTED

input
200000 200000
286470749 280175209 741317063 ...

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

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

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:

input
100000 100000
663307073 663307073 663307073 ...

correct output
329574367
965067805
768744535
691214891
21873594
...

user output
(empty)

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)