QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553865 | #8332. Two in One | Hog_Dawa_IOI | WA | 0ms | 1664kb | C++14 | 1.2kb | 2024-09-08 21:37:08 | 2024-09-08 21:37:09 |
Judging History
answer
#include<stdio.h>
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int t,n,s[100005],ci[100005],beg[100005],end[100005];
int main()
{
scanf("%d",&t);
while(t--)
{
for(int i=1;i<=n;i++) ci[i]=beg[i]=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&s[i]),ci[s[i]]++;
if(!beg[s[i]]) beg[s[i]]=i;
end[s[i]]=i;
}
int k1=0,k2=0;
for(int i=1;i<=n;i++) if(ci[i]>=ci[k1]) k1=i;
for(int i=1;i<=n;i++) if(ci[i]>=ci[k2]&&i!=k1) k2=i;
int ans=ci[k1]|ci[k2],dq=ci[k1]&ci[k2],mi=1,nono=1,cc1=ci[k1],cc2=ci[k2];
while(mi<=dq)
{
if(mi&dq) nono=mi;
mi*=2;
}
int l=max(1,min(beg[k1],beg[k2])),r=max(end[k2],end[k1]);
if((cc1|cc2)==(ans|(nono-1))){printf("%d\n%d %d\n%d %d\n",(ans|(nono-1)),l,r,k1,k2);continue;}
while(l<=r)
{
if(s[l]==k1) cc1--;
if(s[l]==k2) cc2--;
l++;if((cc1|cc2)==(ans|(nono-1)))
{printf("%d\n%d %d\n%d %d\n",
(ans|(nono-1)),l,r,k1,k2);break;}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1664kb
input:
1 7 1 2 3 4 3 2 1
output:
3 3 6 3 2
result:
wrong answer Output contains longer sequence [length = 5], but answer contains 1 elements