Task: | Kyselyt |
Sender: | MojoLake |
Submission time: | 2025-10-19 13:08:52 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | 30 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 20 |
#3 | TIME LIMIT EXCEEDED | 0 |
#4 | TIME LIMIT EXCEEDED | 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 | ACCEPTED | 0.04 s | 2, 3, 4 | details |
#5 | ACCEPTED | 0.05 s | 2, 3, 4 | details |
#6 | ACCEPTED | 0.06 s | 2, 3, 4 | details |
#7 | ACCEPTED | 0.17 s | 3, 4 | details |
#8 | ACCEPTED | 0.09 s | 4 | details |
#9 | ACCEPTED | 0.09 s | 4 | details |
#10 | ACCEPTED | 0.41 s | 4 | details |
#11 | ACCEPTED | 0.11 s | 3, 4 | details |
#12 | ACCEPTED | 0.24 s | 4 | details |
#13 | TIME LIMIT EXCEEDED | -- | 3, 4 | details |
#14 | RUNTIME ERROR | 0.46 s | 4 | details |
#15 | ACCEPTED | 0.72 s | 4 | details |
#16 | ACCEPTED | 0.09 s | 4 | details |
Code
#include <bits/stdc++.h> #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() using namespace std; using ll = long long; const int inf = 1e9; const ll LLInf = 1e18; const int SQR = 3; int main() { cin.tie(0)->sync_with_stdio(0); int n, q; cin >> n >> q; vector<int> a(n); vector<int> vals; for (int&x : a) { cin >> x; vals.push_back(x); } sort(all(vals)); vals.erase(unique(all(vals)), vals.end()); auto comp = [&](int x) { return lower_bound(all(vals), x) - begin(vals); }; map<int, int> inv; for (int& x : a) { int c = comp(x); inv[c] = x; x = c; } map<int, int> cnt; vector<int> high; for (int x : a) { cnt[x]++; if (cnt[x] == SQR) { high.push_back(x); } } vector<vector<int>> pfx(sz(high), vector<int> (n)); for (int j = 0; j < sz(high); ++j) { int x = high[j]; for (int i = 0; i < n; ++i) { if (x == a[i]) pfx[j][i] = 1; if (i) pfx[j][i] += pfx[j][i - 1]; } } auto get_pfx = [&](int j, int l, int r) { return pfx[j][r] - (l == 0 ? 0 : pfx[j][l - 1]); }; auto solve = [&](int l, int r) { int len = r - l + 1; // for (int i = l; i <= r; ++i) { // // cerr << a[i] << " "; // } // cerr << "\n"; if (len >= 2 * SQR) { // must be in high for (int j = 0; j < sz(high); ++j) { // cerr << "j and pfx: " << j << " " << get_pfx(j, l, r) << "\n"; // cerr << "high[j]: " << high[j] << "\n"; if (get_pfx(j, l, r) > len / 2) { return high[j]; } } return -1; } else { vector<int> f(sz(vals)); for (int i = l; i <= r; ++i) { f[a[i]]++; if (f[a[i]] > len / 2) { return a[i]; } } return -1; } }; while (q--) { int l, r; cin >> l >> r; l--; r--; int ans = solve(l, r); if (ans == -1) cout << ans << "\n"; else cout << inv[ans] << "\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: 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: 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: 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 ... |