Task: | Kyselyt |
Sender: | Gomhog |
Submission time: | 2025-10-18 12:15:46 +0300 |
Language: | C++ (C++11) |
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.03 s | 1, 2, 3, 4 | details |
#2 | ACCEPTED | 0.03 s | 1, 2, 3, 4 | details |
#3 | ACCEPTED | 0.03 s | 1, 3, 4 | details |
#4 | ACCEPTED | 0.23 s | 2, 3, 4 | details |
#5 | ACCEPTED | 0.32 s | 2, 3, 4 | details |
#6 | ACCEPTED | 0.18 s | 2, 3, 4 | details |
#7 | ACCEPTED | 0.47 s | 3, 4 | details |
#8 | ACCEPTED | 0.47 s | 4 | details |
#9 | ACCEPTED | 0.63 s | 4 | details |
#10 | ACCEPTED | 0.94 s | 4 | details |
#11 | ACCEPTED | 0.73 s | 3, 4 | details |
#12 | TIME LIMIT EXCEEDED | -- | 4 | details |
#13 | ACCEPTED | 0.22 s | 3, 4 | details |
#14 | ACCEPTED | 0.43 s | 4 | details |
#15 | ACCEPTED | 0.46 s | 4 | details |
#16 | ACCEPTED | 0.64 s | 4 | details |
Code
#include <bits/stdc++.h> #define F first #define S second #define X real() #define Y imag() using namespace std; typedef long long ll; typedef long double ld; const int N = 1<<18; int n; unordered_map<int,int> counts[2*N]; int dom[2*N]; int get_anc(int a, int b) { int lono=N+a; int hino=N+b-1; while (lono < hino) { lono /=2; hino /=2; } return lono; } void make_trees() { for (int i=N+n;i<2*N;i++) dom[i]=-1; for (int d=17;d>=0;d--) { int thres=(1<<(17-d))+1; for (int i = (1<<d);i<(1<<(d+1));i++) { if (dom[2*i] !=-1 && counts[2*i+1].count(dom[2*i]) && counts[2*i+1][dom[2*i]]+counts[2*i][dom[2*i]] >= thres) { dom[i] = dom[2*i]; } else if (dom[2*i+1] !=-1 && counts[2*i].count(dom[2*i+1]) && counts[2*i][dom[2*i+1]]+counts[2*i+1][dom[2*i+1]] >= thres) { dom[i] = dom[2*i+1]; } else dom[i] = -1; for (auto x : counts[2*i]) counts[i][x.F] = x.S; for (auto x : counts[2*i+1]) counts[i][x.F] += x.S; } } } int get_count(int a, int b, int v) { int aa = a+N; int bb = b-1+N; int su = 0; while (aa <=bb) { if (aa%2 == 1) { su += counts[aa].count(v) ? counts[aa][v] : 0; ++aa; } if (bb%2 == 0) { su += counts[bb].count(v) ? counts[bb][v] : 0; --bb; } aa/=2; bb/=2; } return su; } int answer(int a, int b) { int anc = get_anc(a,b); int aa = a+N; int bb = b-1+N; while (aa<=bb) { if (aa%2 == 1) { int tar = dom[aa++]; if (tar != -1 && counts[anc][tar] >= (b-a)/2 + 1) { if (get_count(a,b,tar) >= ((b-a)/2) + 1) return tar; } } if (bb%2 == 0) { int tar = dom[bb--]; if (tar != -1 && counts[anc][tar] >= (b-a)/2 + 1) { if (get_count(a,b,tar) >= ((b-a)/2) + 1) return tar; } } aa/=2; bb/=2; } return -1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q; cin>>n>>q; for (int i=0;i<n;i++) { cin>>dom[N+i]; counts[N+i][dom[N+i]]=1; } make_trees(); for (int qu=0;qu<q;qu++) { int a, b; cin>>a>>b; cout << answer(a-1,b)<<"\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: 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 ... |