QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677515#8332. Two in OneYaimsea#WA 30ms6184kbC++201.8kb2024-10-26 12:27:442024-10-26 12:27:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 12:27:45]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:6184kb
  • [2024-10-26 12:27:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int m=16;
vector<int> E[100010];
int n,ans,num[100010],c[100010],minr[100010],maxnum[100010];
int clac[100010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int i,j,id,tot,vis,tnum,T;
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(i=1;i<=n;++i)
		{
			E[i].push_back(0);
			minr[i]=1;
		}
		minr[0]=1;
		for(i=1;i<=n;++i)
		{
			cin>>c[i];
			E[c[i]].push_back(i);
			++num[c[i]];
		}
		for(i=1;i<=n;++i)
			maxnum[i]=num[i];
		ans=0;
		for(i=m;i>=0;--i)
		{
			tot=0;
			for(j=1;j<=n;++j)
			{
				if(num[j]&(1<<i))
					id=j,++tot;
			}
			if(tot==1)
			{
				ans|=(1<<i);
				tnum=(num[id]&((1<<i)-1))+1;
				for(j=0;j<=num[id];++j)
				{
					if(j>=tnum)
						minr[E[id][j]]=n+1;
					else
						minr[E[id][j]]=max(minr[E[id][j]],E[id][num[i]-(tnum-j)+1]+1);
				}
				for(j=1;j<=n;++j)
					minr[j]=max(minr[j],minr[j-1]);
				for(j=1;j<=n;++j)
					maxnum[j]=0,clac[j]=0;
				for(j=1;j<=n;++j)
				{
					++clac[c[j]];
					tnum=E[c[j]].end()-lower_bound(E[c[j]].begin(),E[c[j]].end(),minr[j]);
					maxnum[c[j]]=max(maxnum[c[j]],clac[c[j]]+tnum);
				}
				for(j=1;j<=n;++j)
				{
					tnum=E[j].end()-lower_bound(E[j].begin(),E[j].end(),minr[0]);
					maxnum[j]=max(maxnum[j],tnum);
				}
			}
			else	if(tot>=2)
			{
				ans|=(1<<i);
				if(!i)
					break;
				vis=0;
				for(j=1;j<=n;++j)
				{
					if(num[j]&(1<<i))
					{
						if(maxnum[j]>(num[j]&((1<<i)-1)))
						{
							vis=1;
							break;
						}
					}
				}
				if(vis)
				{
					for(j=i-1;j>=0;--j)
						ans|=(1<<j);
					break;
				}
			}
		}
		cout<<ans<<'\n';
		for(i=1;i<=n;++i)
		{
			E[i].clear();
			num[i]=0;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

1
7
1 2 3 4 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

1
9
1 1 1 1 1 2 2 2 2

output:

7

result:

ok 1 number(s): "7"

Test #3:

score: 0
Accepted
time: 22ms
memory: 6184kb

input:

50
10000
72 65 90 94 67 93 41 43 54 83 31 34 38 37 44 42 92 63 66 79 90 45 41 40 19 54 34 90 13 74 40 77 41 57 74 86 91 79 34 39 21 88 90 57 23 31 8 15 80 27 45 38 53 96 51 82 70 71 19 75 62 95 31 67 99 97 94 29 90 7 95 82 61 98 62 77 43 65 66 30 41 69 38 79 51 9 63 77 13 30 72 70 67 93 92 45 74 50 ...

output:

255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255

result:

ok 50 numbers

Test #4:

score: -100
Wrong Answer
time: 30ms
memory: 5620kb

input:

79114
7
1 2 4 3 2 3 7
7
1 2 4 7 4 1 5
6
4 2 2 4 2 1
7
1 2 1 4 7 3 2
7
1 2 4 7 1 1 3
7
1 2 6 1 5 2 5
6
5 2 6 1 2 5
7
1 1 7 6 6 5 2
7
1 2 5 6 6 7 7
7
1 1 2 7 2 3 6
7
1 1 1 4 6 2 2
7
1 1 5 7 3 5 2
7
1 1 7 6 2 2 5
6
4 3 4 6 3 1
6
4 4 3 2 3 1
7
1 1 2 3 7 6 2
6
1 2 5 6 3 4
7
1 1 1 1 4 7 6
6
2 6 6 2 5 3
6
...

output:

3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
1
5
3
3
3
3
3
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
7
3
3
3
3
5
3
3
3
5
3
3
3
3
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
3
5
3
3
3
1
3
3
3
3
3
3
5
3
3
3
3
3
3
3
3
3
3
...

result:

wrong answer 97th numbers differ - expected: '6', found: '7'