| Task: | Kyselyt |
| Sender: | Kuha |
| Submission time: | 2025-10-18 13:02:01 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 20 |
| #3 | ACCEPTED | 30 |
| #4 | ACCEPTED | 40 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3, 4 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2, 3, 4 | details |
| #3 | ACCEPTED | 0.01 s | 1, 3, 4 | details |
| #4 | ACCEPTED | 0.22 s | 2, 3, 4 | details |
| #5 | ACCEPTED | 0.24 s | 2, 3, 4 | details |
| #6 | ACCEPTED | 0.37 s | 2, 3, 4 | details |
| #7 | ACCEPTED | 0.40 s | 3, 4 | details |
| #8 | ACCEPTED | 0.47 s | 4 | details |
| #9 | ACCEPTED | 0.51 s | 4 | details |
| #10 | ACCEPTED | 0.92 s | 4 | details |
| #11 | ACCEPTED | 0.38 s | 3, 4 | details |
| #12 | ACCEPTED | 0.78 s | 4 | details |
| #13 | ACCEPTED | 0.24 s | 3, 4 | details |
| #14 | ACCEPTED | 0.47 s | 4 | details |
| #15 | ACCEPTED | 0.46 s | 4 | details |
| #16 | ACCEPTED | 0.43 s | 4 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:55:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if (tried[x] || 2 * mp[x].size() <= len) continue;
| ~~~~~~~~~~~~~~~~~^~~~~~Code
#include <bits/stdc++.h>
#define N (1<<18)
using namespace std;
int v[N];
int comp[N];
vector<int> mp[N];
map<int, int> enc;
map<int, int> de;
int pot[N];
int tried[N];
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
srand(time(0));
int n, q;
cin>>n>>q;
vector<int> vals;
for (int i = 1; i <= n; i++) {
cin>>v[i];
vals.push_back(v[i]);
}
int g = 1;
for (int i = 1; i < N; i++) {
if (2 * g <= i) g *= 2;
pot[i] = g;
}
vals.push_back(-1);
sort(vals.begin(), vals.end());
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (vals[i] != vals[i - 1]) cnt++;
enc[vals[i]] = cnt;
de[cnt] = vals[i];
}
for (int i = 1; i <= n; i++) {
comp[i] = enc[v[i]];
mp[comp[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
if (mp[comp[i]].back() != n + 1) mp[comp[i]].push_back(n + 1);
}
while (q --> 0) {
int l, r;
cin>>l>>r;
vector<int> att;
for (int t = 0; t < 21; t++) {
int len = r - l + 1;
int i = l + (rand() % len);
int x = comp[i];
if (tried[x] || 2 * mp[x].size() <= len) continue;
tried[x] = 1;
att.push_back(x);
int li = -1;
int ri = -1;
int wl = mp[x].size();
for (int inc = pot[wl + 1]; inc >= 1; inc /= 2) {
if (li + inc < wl && mp[x][li + inc] < l) li += inc;
}
ri = li;
for (int inc = pot[wl - li + 1]; inc >= 1; inc /= 2) {
if (ri + inc < wl && mp[x][ri + inc] <= r) ri += inc;
}
if (2 * (ri - li) > len) {
cout<<de[x]<<endl;
goto end;
}
}
cout<<-1<<endl;
end:;
for (int i : att) {
tried[i] = 0;
}
}
}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: ACCEPTED
| 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 |
|---|
| 1 1 1 1 1 ... |
Test 9
Group: 4
Verdict: ACCEPTED
| 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 |
|---|
| 2 2 2 2 2 ... |
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: ACCEPTED
| input |
|---|
| 100000 100000 613084013 1000000000 411999902... |
| correct output |
|---|
| -1 -1 -1 -1 1000000000 ... |
| user output |
|---|
| -1 -1 -1 -1 1000000000 ... |
Test 12
Group: 4
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 613084013 1000000000 411999902... |
| correct output |
|---|
| 1000000000 1000000000 -1 1000000000 -1 ... |
| user output |
|---|
| 1000000000 1000000000 -1 1000000000 -1 ... |
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: ACCEPTED
| input |
|---|
| 200000 200000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 107596959 249558965 679275202 760593154 725418770 ... |
| user output |
|---|
| 107596959 249558965 679275202 760593154 725418770 ... |
Test 15
Group: 4
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 211070558 49212342 651109313 264549124 651109313 ... |
| user output |
|---|
| 211070558 49212342 651109313 264549124 651109313 ... |
Test 16
Group: 4
Verdict: ACCEPTED
| 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 |
|---|
| 1 2 1 1 1 ... |
