Task: | Kyselyt |
Sender: | jlaire |
Submission time: | 2025-10-18 04:38:18 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 60 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 20 |
#3 | ACCEPTED | 30 |
#4 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.06 s | 1, 2, 3, 4 | details |
#2 | ACCEPTED | 0.06 s | 1, 2, 3, 4 | details |
#3 | ACCEPTED | 0.06 s | 1, 3, 4 | details |
#4 | ACCEPTED | 0.23 s | 2, 3, 4 | details |
#5 | ACCEPTED | 0.27 s | 2, 3, 4 | details |
#6 | ACCEPTED | 0.33 s | 2, 3, 4 | details |
#7 | ACCEPTED | 0.70 s | 3, 4 | details |
#8 | ACCEPTED | 0.44 s | 4 | details |
#9 | ACCEPTED | 0.53 s | 4 | details |
#10 | TIME LIMIT EXCEEDED | -- | 4 | details |
#11 | ACCEPTED | 0.49 s | 3, 4 | details |
#12 | TIME LIMIT EXCEEDED | -- | 4 | details |
#13 | ACCEPTED | 0.22 s | 3, 4 | details |
#14 | ACCEPTED | 0.40 s | 4 | details |
#15 | ACCEPTED | 0.43 s | 4 | details |
#16 | ACCEPTED | 0.32 s | 4 | details |
Code
#include <iostream> #include <map> #include <tuple> #include <utility> using namespace std; using pii = pair<int,int>; const int N=1<<18; map<int,int> merge(map<int,int> M, const map<int,int>& m) { for (auto [k,v]:m) M[k]+=v; return M; } // (boss, delta) pii operator+(pii a, pii b) { if (a.first == b.first) { return pii(a.first, a.second + b.second); } return a.second >= b.second ? pii(a.first, a.second - b.second) : pii(b.first, b.second - a.second); } struct Node { int boss = 0; int delta = 0; map<int,int> M; int cnt(int x) const { auto it = M.find(x); return it==M.end() ? 0 : it->second; } void init(int x) { boss = x; delta = 1; M[x] = 1; } void init(const Node& a, const Node& b) { M = a.M.size()>=b.M.size() ? merge(a.M,b.M) : merge(b.M,a.M); tie(boss, delta) = pii(a.boss, a.delta) + pii(b.boss, b.delta); } }; Node T[4*N]; void init(int t=1, int tl=0, int tr=N-1) { if (tl>=tr) return; int tm = (tl+tr)/2; init(2*t, tl, tm); init(2*t+1, tm+1, tr); T[t].init(T[2*t], T[2*t+1]); } pii getboss(int t, int ql, int qr, int tl=0, int tr=N-1) { if (ql<=tl && qr>=tr) return pii(T[t].boss, T[t].delta); if (qr<tl || ql>tr) return pii(0, 0); int tm = (tl+tr)/2; return getboss(2*t, ql, qr, tl, tm) + getboss(2*t+1, ql, qr, tm+1, tr); } int getcnt(int t, int ql, int qr, int x, int tl=0, int tr=N-1) { if (ql<=tl && qr>=tr) return T[t].cnt(x); if (qr<tl || ql>tr) return 0; int tm = (tl+tr)/2; return getcnt(2*t, ql, qr, x, tl, tm) + getcnt(2*t+1, ql, qr, x, tm+1, tr); } int main() { cin.tie(0)->sync_with_stdio(0); int n,q; cin>>n>>q; for (int i=0; i<n; i++) { int x; cin>>x; T[N+i].init(x); } init(); for (int a,b; cin>>a>>b;) { a--, b--; auto [boss,_] = getboss(1,a,b); if (boss && 2*getcnt(1,a,b,boss)>b-a+1) { cout << boss << '\n'; } else { 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: 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: TIME LIMIT EXCEEDED
input |
---|
200000 200000 286470749 280175209 741317063 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
(empty) |
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: TIME LIMIT EXCEEDED
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: 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 ... |