Task: | Kyselyt |
Sender: | Grez |
Submission time: | 2025-10-18 18:52:58 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 10 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
#4 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2, 3, 4 | details |
#2 | ACCEPTED | 0.00 s | 1, 2, 3, 4 | details |
#3 | ACCEPTED | 0.00 s | 1, 3, 4 | details |
#4 | WRONG ANSWER | 0.23 s | 2, 3, 4 | details |
#5 | WRONG ANSWER | 0.23 s | 2, 3, 4 | details |
#6 | ACCEPTED | 0.25 s | 2, 3, 4 | details |
#7 | ACCEPTED | 0.30 s | 3, 4 | details |
#8 | WRONG ANSWER | 0.47 s | 4 | details |
#9 | WRONG ANSWER | 0.47 s | 4 | details |
#10 | ACCEPTED | 0.64 s | 4 | details |
#11 | WRONG ANSWER | 0.28 s | 3, 4 | details |
#12 | WRONG ANSWER | 0.59 s | 4 | details |
#13 | TIME LIMIT EXCEEDED | -- | 3, 4 | details |
#14 | RUNTIME ERROR | 0.49 s | 4 | details |
#15 | TIME LIMIT EXCEEDED | -- | 4 | details |
#16 | WRONG ANSWER | 0.46 s | 4 | details |
Code
#include <iostream> #include <unordered_map> #include <list> using namespace std; struct joo { int key; int amo; short* counts; }; bool joodesc(const joo& a, const joo& b) { return a.amo > b.amo; } int main() { int n, q; cin >> n; cin >> q; // Dynamically allocate an array int* arr = new int[n]; unordered_map<int, joo> m = {}; // Assign values to the array elements for (int i = 0; i < n; i++) { cin >> arr[i]; joo s = m[arr[i]]; s.key = arr[i]; s.amo++; m[arr[i]] = s; } list<joo> relevant = {}; for (auto& it : m) { if (it.second.amo > 1) { it.second.counts = new short[n](); relevant.push_back(it.second); } } for (int i = 0; i < n; i++) { joo s = m[arr[i]]; if (s.amo > 1) s.counts[i] = 1; } for (auto& it : m) { if (it.second.amo > 1) { auto c = it.second.counts; for (int i = 1; i < n; i++) { c[i] = c[i - 1] + c[i]; } } } relevant.sort(joodesc); while (q) { q--; int a, b; cin >> a; cin >> b; if (a == b) { cout << arr[a - 1] << endl; continue; } int half = (b - a + 1) / 2; int found = -1; for (auto pp : relevant) { if (pp.amo <= half) break; if (a < 2) { if (pp.counts[b - 1] > half) { found = pp.key; break; } } if ((pp.counts[b-1] - pp.counts[a-2])>half) { found = pp.key; break; } } cout << found << 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: WRONG ANSWER
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: WRONG ANSWER
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 -1 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: WRONG ANSWER
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: WRONG ANSWER
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 |
---|
-1 2 -1 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: WRONG ANSWER
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: WRONG ANSWER
input |
---|
200000 200000 613084013 1000000000 411999902... |
correct output |
---|
1000000000 1000000000 -1 1000000000 -1 ... |
user output |
---|
-1 1000000000 -1 1000000000 -1 ... |
Test 13
Group: 3, 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100000 663307073 663307073 663307073 ... |
correct output |
---|
329574367 965067805 768744535 691214891 21873594 ... |
user output |
---|
(empty) |
Test 14
Group: 4
Verdict: RUNTIME ERROR
input |
---|
200000 200000 663307073 663307073 663307073 ... |
correct output |
---|
107596959 249558965 679275202 760593154 725418770 ... |
user output |
---|
(empty) |
Test 15
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 200000 663307073 663307073 663307073 ... |
correct output |
---|
211070558 49212342 651109313 264549124 651109313 ... |
user output |
---|
(empty) |
Test 16
Group: 4
Verdict: WRONG ANSWER
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 -1 -1 -1 -1 ... |