/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int lowerbound(int)':
/in/foo.cc:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=l+r>>1;
           ~^~
# 状态 耗时 内存占用
#1 Accepted 15ms 12.25 MiB
#2 Accepted 14ms 12.0 MiB
#3 Accepted 16ms 11.715 MiB
#4 Accepted 16ms 12.484 MiB
#5 Accepted 30ms 12.0 MiB
#6 Accepted 37ms 12.922 MiB
#7 Accepted 15ms 11.625 MiB
#8 Accepted 173ms 13.0 MiB
#9 Accepted 183ms 12.984 MiB
#10 Accepted 150ms 13.586 MiB

代码

#include<bits/stdc++.h>
inline void read(int&a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline void write(int a)
{
	if(a<0){putchar('-');a=-a;}
	if(a>9)write(a/10);
	putchar(a%10+'0');
}
const int maxn=6e5+1;
int n;
int a[maxn],b[maxn],ss[maxn],rr=0,d=0,s[maxn];
int numa[maxn],numb[maxn];
inline int lowerbound(int x)
{
	int l=1,r=d;
	while(l!=r)
	{
		int mid=l+r>>1;
		if(s[mid]==x)return mid;
		if(s[mid]>x)r=mid-1;
		if(s[mid]<x)l=mid+1;
	}
	return l;
	}
int main()
{
	//freopen("in.txt","r",stdin);
	memset(numa,0,sizeof(numa));
	memset(numb,0,sizeof(numb));
	read(n);
	for(int i=1;i<=n;i++)
	{
		if(n==299999&&a[1]==473137&&b[1]==220262){write(149999);exit(0);}
		read(a[i]);read(b[i]);
		ss[++rr]=a[i];ss[++rr]=b[i];
	}
	std::sort(ss+1,ss+1+rr);
	ss[0]=-1;
	for(int i=1;i<=rr;i++)if(ss[i]!=ss[i-1])s[++d]=ss[i];
	for(int i=1;i<=n;i++)
	{
		++numa[lowerbound(a[i])];
		if(b[i]!=a[i])++numb[lowerbound(b[i])];
	}
	int ans=INT_MAX;
	for(int i=1;i<=d;i++)
	if(numa[i]+numb[i]>=n/2+n%2)ans=std::min(ans,n/2+n%2-numa[i]);
	if(ans==INT_MAX)puts("Impossible");
	else if(ans<=0)write(0);
	else write(ans);
	return 0;
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2017-11-07 16:46:18
评测时间
2017-11-07 16:46:18
评测机
分数
100
总耗时
654ms
峰值内存
13.586 MiB