| Task: | Kyselyt |
| Sender: | Sisuaski |
| Submission time: | 2025-10-17 20:33:54 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| #4 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.02 s | 1, 2, 3, 4 | details |
| #2 | WRONG ANSWER | 0.02 s | 1, 2, 3, 4 | details |
| #3 | WRONG ANSWER | 0.02 s | 1, 3, 4 | details |
| #4 | ACCEPTED | 0.61 s | 2, 3, 4 | details |
| #5 | WRONG ANSWER | 0.82 s | 2, 3, 4 | details |
| #6 | WRONG ANSWER | 0.88 s | 2, 3, 4 | details |
| #7 | WRONG ANSWER | 0.40 s | 3, 4 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #10 | WRONG ANSWER | 0.82 s | 4 | details |
| #11 | WRONG ANSWER | 0.64 s | 3, 4 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #13 | WRONG ANSWER | 0.41 s | 3, 4 | details |
| #14 | WRONG ANSWER | 0.83 s | 4 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 4 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 4 | details |
Code
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MN = 1<<19;
int xs[MN];
int xc[MN];
int tree[2*MN];
vector<int> pos[MN];
int count(int y, int p) {
auto& v = pos[y];
return lower_bound(v.begin(),v.end(),p)-v.begin();
}
int count(int y, int a, int b) {
if (y==0) return 0;
return count(y,b) - count(y,a);
}
int build(int i, int a, int b) {
if (b-a<=1) return tree[i];
int m = (a+b)/2;
int x = build(2*i,a,m);
int y = build(2*i+1,m,b);
if (x==y) return tree[i]=x;
int cx = count(x,a,b);
int cy = count(y,a,b);
int res = tree[i] = cx>cy ? x : cy>cx ? y : 0;
return res;
}
int solve(int a, int b, int l, int r, int i) {
if (l>=a && r<=b) return tree[i];
if (r<=a || l>=b) return 0;
int m = (l+r)/2;
int x = solve(a,b,l,m,2*i);
int y = solve(a,b,m,r,2*i+1);
if (x==y) return x;
int cx = count(x,l,r);
int cy = count(y,l,r);
return cx>cy ? x : cy>cx ? y : 0;
}
int main() {
int n,q;cin>>n>>q;
for(int i=0;i<n;++i)cin>>xs[i],xc[i]=xs[i];
xc[n]=-1;
sort(xc,xc+n+1);
int k = unique(xc,xc+n+1)-xc;
for(int i=0; i<n; ++i) {
int y = lower_bound(xc,xc+k,xs[i])-xc;
tree[MN+i]=y;
pos[y].push_back(i);
}
build(1,0,MN);
while(q--){
int a,b;cin>>a>>b;
cout<<xc[solve(a-1,b,0,MN,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 ... Truncated |
Test 2
Group: 1, 2, 3, 4
Verdict: WRONG ANSWER
| 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 ... Truncated |
Test 3
Group: 1, 3, 4
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 5 19 44 88 14 79 50 44 14 99 7... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| 14 -1 9 -1 35 ... Truncated |
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 ... Truncated |
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 2 1 ... Truncated |
Test 6
Group: 2, 3, 4
Verdict: WRONG ANSWER
| 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 |
|---|
| 3 3 3 1 3 ... Truncated |
Test 7
Group: 3, 4
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 141307 493258596 365539511 222... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| -1 -1 178786754 -1 927626025 ... Truncated |
Test 8
Group: 4
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
Test 9
Group: 4
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
Test 10
Group: 4
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 286470749 280175209 741317063 ... |
| correct output |
|---|
| -1 -1 -1 -1 -1 ... |
| user output |
|---|
| -1 581749513 -1 -1 527322418 ... Truncated |
Test 11
Group: 3, 4
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 613084013 1000000000 411999902... |
| correct output |
|---|
| -1 -1 -1 -1 1000000000 ... |
| user output |
|---|
| 1000000000 1000000000 1000000000 1000000000 1000000000 ... Truncated |
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: WRONG ANSWER
| input |
|---|
| 100000 100000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 329574367 965067805 768744535 691214891 21873594 ... |
| user output |
|---|
| -1 965067805 -1 691214891 -1 ... Truncated |
Test 14
Group: 4
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 663307073 663307073 663307073 ... |
| correct output |
|---|
| 107596959 249558965 679275202 760593154 725418770 ... |
| user output |
|---|
| -1 -1 679275202 760593154 -1 ... Truncated |
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: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
