记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:76:8: warning: 'b2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   a=crt(a1,w1,b2,w2),b=crt(b1,w1,a2,w2);
     ~~~^~~~~~~~~~~~~
/in/foo.cc:65:10: warning: 'a2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ll a=crt(a1,w1,a2,w2),b=crt(b1,w1,b2,w2);
       ~~~^~~~~~~~~~~~~
/in/foo.cc:65:29: warning: 'b1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ll a=crt(a1,w1,a2,w2),b=crt(b1,w1,b2,w2);
                          ~~~^~~~~~~~~~~~~
/in/foo.cc:76:8: warning: 'a1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   a=crt(a1,w1,b2,w2),b=crt(b1,w1,a2,w2);
     ~~~^~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 1ms 472.0 KiB
#2 Accepted 1ms 548.0 KiB
#3 Accepted 10ms 496.0 KiB
#4 Accepted 15ms 496.0 KiB
#5 Accepted 294ms 492.0 KiB
#6 Accepted 283ms 492.0 KiB
#7 Accepted 286ms 492.0 KiB
#8 Accepted 289ms 512.0 KiB
#9 Accepted 267ms 504.0 KiB
#10 Accepted 279ms 500.0 KiB

代码

#include <cstdio>
#include <algorithm>
using namespace std;
int read(){
    int val=0;
    char c=getchar();
    while(c<'0' || c>'9')
    	c=getchar();
    while(c>='0' && c<='9')
    	val=val*10+c-'0',c=getchar();
    return val;
}
typedef long long ll;
void exgcd(ll a,ll b,ll& d,ll& x,ll& y){ //ax+by=d
	if (!b){
		d=a;
		x=1;
		y=0;
		return;
	}else{
		exgcd(b,a%b,d,y,x);
		y-=x*(a/b);
	}
}
ll crt(ll a,ll m,ll b,ll n){ //x=km+a=tn+b->km-tn=b-a
	ll d,k,t; 
	exgcd(m,n,d,k,t);
	ll w=(b-a);
	//printf("m=%lld n=%lld t=%lld k=%lld w=%lld\n",m,n,t,k,w);
	ll lcm=m*n;
	return (k*w*m+a)%lcm;
}
const int p1=98869,p2=98873;
bool cnt1[98869],cnt2[98873];
int main(){
	int n=read(),k=read(),xs=0;
	while(n--){
		int x=read();
		xs^=x;
		cnt1[x%p1]^=1;
		cnt2[x%p2]^=1;
	}
	if (k==1){
		printf("%d",xs);
		return 0;
	}
	ll a1,b1,a2,b2;
	bool flag=false;
	for(int i=0;i<p1;i++){
		if (!cnt1[i])
			continue;
		if (flag)
			b1=i;
		else a1=i,flag=true;
	}
	flag=false;
	for(int i=0;i<p2;i++){
		if (!cnt2[i])
			continue;
		if (flag)
			b2=i;
		else a2=i,flag=true;
	}
	ll w1=p1,w2=p2;
	ll a=crt(a1,w1,a2,w2),b=crt(b1,w1,b2,w2);
	if (a<0)
		a+=w1*w2;
	if (b<0)
		b+=w1*w2;
	if ((a^b)==xs){
		if (a>b)
			swap(a,b);
		printf("%lld %lld",a,b);
	}
	else{
		a=crt(a1,w1,b2,w2),b=crt(b1,w1,a2,w2);
		if (a<0)
			a+=w1*w2;
		if (b<0)
			b+=w1*w2;
		if (a>b)
			swap(a,b);
		printf("%lld %lld",a,b);
	}
}

信息

递交者
类型
递交
题目
亚由题
语言
C++
递交时间
2017-06-23 19:39:14
评测时间
2017-06-23 19:39:14
评测机
分数
100
总耗时
1730ms
峰值内存
548.0 KiB