QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#867641#9684. 倾诉lgvc0 3ms55164kbC++234.2kb2025-01-23 20:53:222025-01-23 20:53:22

Judging History

This is the latest submission verdict.

  • [2025-01-23 20:53:22]
  • Judged
  • Verdict: 0
  • Time: 3ms
  • Memory: 55164kb
  • [2025-01-23 20:53:22]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
	if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
	*pp++=ch;
}
inline void pcc(){
	fwrite(buf2,1,pp-buf2,stdout);
	pp=buf2;
}
inline int read(void){
	int w=1;
	register int x(0);register char c(getchar());
	while(c<'0'||c>'9'){if(c=='-') w=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return w*x;
}
void write(int x){
	static int sta[20];
	int top=0;
	do{
		sta[top++]=x%10,x/=10;
	}while(x);
	while(top) pc(sta[--top]+48);
}
void we(int x){
	write(x);
	pc('\n');
}
int C,T,N,M,a[100009],b[100009],vf[100009],ss,p[62][100009];
struct n_t{
	int a,b;
};
std::vector<n_t> t[20009];
int ct,tx;
int qr(std::vector<n_t> tq) {
	int as=ss;
	for(int i=0;i<tq.size();i++) {
		as^=a[tq[i].a];
		as^=(a[tq[i].a]+tq[i].b);
	}
	return as;
}
inline bool cmp(n_t x,n_t y) {
	return x.a<y.a;
}
inline bool fd(int x,std::vector<n_t> y) {
	for(int i=0;i<y.size();i++) {
		if(y[i].a==x) return 1;
	}
	return 0;
}
int vc(std::vector<n_t> tq) {
	tx++;
	for(int i=0;i<tq.size();i++) vf[tq[i].a]=tx;
	return tx;
}
int sv(std::vector<n_t> tq) {
	int aq=0;
	int ti=vc(tq);
	for(int i=60;i>=0;i--) {
		if((qr(tq)>>i)&1) {
			bool zt=0;
			for(int j=1;j<=N;j++) {
				int t=p[i][j];
				if((a[t]>>i)%2==0) {
					if(vf[t]==ti) continue;
					int x=(a[t]&((1ll<<i)-1));
					aq+=(1ll<<i)-x;
					tq.push_back((n_t){t,(1ll<<i)-x});
					vf[t]=ti;
					zt=1;
					break;
				} else {
					break;
				}
			}
			if(!zt) {
				if(0==tq.size()) {
					return (1ll<<62);
				}
				tq[0].b+=(1ll<<i);
				aq+=(1ll<<i);
			}
		}
	}	
	return aq;	
}
std::unordered_map<int,int> vi;
void cl(std::vector<n_t> tq) {
	if(ct==M) return;
	std::sort(tq.begin(),tq.end(),cmp);
	int vm=tq.size();
	for(int j=0;j<tq.size();j++) {
		vm=(vm*137+tq[j].a)%10000000000000061ll;
		vm=(vm*137+tq[j].b)%10000000000000061ll;
	}
	if(vi[vm]) return;
	vi[vm]=1;
	ct++;
	t[ct]=tq;
}
bool qj(int i,std::vector<n_t> tq,int va) {	
	if(va!=sv(tq)) return 0;
	if(i==-1) {
		cl(tq);
		return 1;
	}
	if((qr(tq)>>i)&1) {
		//if(i==0) printf("!!!\n");
		int ans=(1ll<<61);
		for(int j=1;j<=N;j++) {
			int t=p[i][j];
			if(fd(t,tq)) continue;
			if((a[t]>>i)%2==0) {
			//	assert(t);
				int x=(a[t]&((1ll<<i)-1));
				tq.push_back((n_t){t,(1ll<<i)-x});
				if(!qj(i-1,tq,va-(1ll<<i)+x)) return 1;
				tq.pop_back();
				if(ct==M) return 1;
			} else break;
		}
		for(int j=0;j<tq.size();j++) {
			tq[j].b+=(1ll<<i);
			if(!qj(i-1,tq,va-(1ll<<i))) return 1;
			if(ct==M) return 1;
			tq[j].b-=(1ll<<i);
		}
	} else {
		qj(i-1,tq,va);
	}
	return 1;
}
#define INF_LL 0x3f3f3f3f3f3f3f3f
int tp;
bool cmq(int x,int y) {
	x=a[x];
	y=a[y];
	if(((x^y)>>tp)&1) 
		return (x&((1ll<<tp+1)-1))<(y&((1ll<<tp+1)-1));
	return (x&((1ll<<tp)-1))>(y&((1ll<<tp)-1));
}
signed main(void) {
	C=read();T=read();
	while(T--) {
		vi.clear();
		N=read();M=read();
		ct=0;
		ss=0;
		for(int i=1;i<=N;i++) {
			a[i]=read();
			b[i]=a[i];
			ss^=a[i];
		}
		if(ss==0) {
			printf("0\n1\n0\n\n\n");
			continue;
		}
		for(int i=0;i<=60;i++) {
			for(int j=1;j<=N;j++) p[i][j]=j;
			tp=i;
			std::sort(p[i]+1,p[i]+N+1,cmq);
		}
		int ans=INF_LL;
		for(int i=0;i<=60;i++) {
			std::vector<n_t> tq;
			int t=p[i][1];
			if((a[t]>>i)&1) continue;
			int x=(a[t]&((1ll<<i)-1));
			tq.push_back((n_t){t,(1ll<<i)-x});
			ans=std::min(ans,sv(tq)+(1ll<<i)-x);
		}
		for(int i=0;i<=60;i++) {
			std::vector<n_t> tq;
			for(int j=1;j<=N;j++) {
				int t=p[i][j];
				if((a[t]>>j)&1) break;
				int x=(a[t]&((1ll<<i)-1));
				tq.push_back((n_t){t,(1ll<<i)-x});
				if(!qj(60,tq,ans-(1ll<<i)+x)) break;
				if(ct==M) break;
				tq.pop_back();
			}
		}
//		qj(60,tq,ans);
		printf("%lld\n%lld\n",ans,ct);
		for(int i=1;i<=ct;i++) {
			printf("%lld\n",(int)t[i].size());
			for(int j=0;j<t[i].size();j++) printf("%lld ",t[i][j].a);
			printf("\n");
			for(int j=0;j<t[i].size();j++) printf("%lld ",t[i][j].b);
			printf("\n");
			t[i]=t[0];
		}	
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

5
6 1
11764 28428 28179 18698 6443 20288
6 3
29 17548 61962 31242 8172 4107
6 15
7 2 239427 137145 171239 3
6 4
294 211 407 190 2 2
6 5
197190 265870 12121 144584 21313 14169

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

score: 0
Wrong Answer
time: 3ms
memory: 55164kb

input:

1666
6 1
282 719 29 355 388 275
6 1
348 766 91 299 474 96
6 23
5 2 8554 8554 8554 2
6 1
84 195 23 37 120 117
6 3
8 3 51 62 28 5
6 3
3 64 64 4 4 2
6 9
5 552 552 552 552 5
6 3
3611 1144 417 3461 459 755
6 3
777 315 1007 5 2 1061
6 6
1300 2101 4 1877 360 2434
6 1
384 713 168 25 524 390
6 3
203 18 305 1...

output:

721
0
7446
355
7
2 4 5 6 8 15 25 
1 1 4 7426 5 1 8 
7
2 4 5 6 8 25 29 
1 1 4 7426 5 8 1 
7
2 4 5 6 8 25 27 
1 1 4 7426 5 8 1 
7
2 4 5 6 8 21 25 
1 1 4 7426 5 1 8 
7
2 4 5 6 8 19 25 
1 1 4 7426 5 1 8 
7
2 4 5 6 8 18 25 
1 1 4 7426 5 1 8 
7
2 4 5 6 8 17 25 
1 1 4 7426 5 1 8 
7
2 4 5 6 8 16 25 
1 1 4 7...

result:

wrong answer 1st lines differ - expected: '110000100100000', found: '721'

Subtask #6:

score: 0
Time Limit Exceeded

Test #80:

score: 0
Time Limit Exceeded

input:

3333
6 1000000000
131727 7 4 170194 6 59263
6 1000000000
417714 286613 7 310122 6 4
6 1000000000
63764 2430 2696 6699 8478 22261
6 1000000000
217 131 6 1487 2927 2
6 1000000000
26225 27991 3842 72525 4521 5231
6 1000000000
34409 26001 23563 19345 30764 24919
6 1000000000
97981 138532 59280 82393 128...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #4:

0%