QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449198#8523. Puzzle IIkkkgjyismine4WA 1ms4548kbC++232.3kb2024-06-20 19:57:152024-06-20 19:57:16

Judging History

This is the latest submission verdict.

  • [2024-06-20 19:57:16]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 4548kb
  • [2024-06-20 19:57:15]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
int n,k,rt,rt1,tot;
char a[300005],b[300005];
struct Node{int son[2],op,key,sz,pos[2];}t[600005];
#define ls(p) t[p].son[0]
#define rs(p) t[p].son[1]
#define op(p) t[p].op
#define key(p) t[p].key
#define sz(p) t[p].sz
void Add(int p,int q,int d){for(int i=0;i<2;++i)if(t[q].pos[i])t[p].pos[i]=t[q].pos[i]+d;}
void pp(int p){
	if(!p)return;
	sz(p)=1;t[p].pos[0]=t[p].pos[1]=0;
	t[p].pos[op(p)]=sz(ls(p))+1;
	if(ls(p))sz(p)+=sz(ls(p)),Add(p,ls(p),0);
	if(rs(p))sz(p)+=sz(rs(p)),Add(p,rs(p),sz(ls(p))+1);
}
int merge(int u,int v){
	if(!u||!v)return (u|v);
	if(key(u)<key(v)){
		rs(u)=merge(rs(u),v),pp(u);
		return u;
	}else{
		ls(v)=merge(u,ls(v)),pp(v);
		return v;
	}
}
void split(int u,int &x,int &y,int c){
	if(!u){x=y=0;return;}
	if(sz(ls(u))+1<=c)x=u,split(rs(u),rs(x),y,c-sz(ls(u))-1);
	else y=u,split(ls(u),x,ls(y),c);pp(u);
}
void cg(int a,int b,int c){
	int x,y,z,X,Y,Z;
	split(rt,x,y,a-1),split(y,y,z,c);
	split(rt1,X,Y,b-1),split(Y,Y,Z,c);
	swap(y,Y);
	rt=merge(x,y),rt=merge(rt,z);
	rt1=merge(X,Y),rt1=merge(rt1,Z);
}
int Lst(int u,int c){
	int x=u-c+1;
	while(x<=0)x+=n;
	while(x>n)x-=n;
	return x;
}
int Nxt(int u,int c){
	int x=u+c-1;
	while(x<=0)x+=n;
	while(x>n)x-=n;
	return x;
}
int len[10],tt;
void opr(int p,int q){
	printf("%d %d\n",p,q);
//	for(int i=p,j=q,c=1;c<=k;i=i%n+1,j=j%n+1,++c)swap(a[i],b[j]);
	if(p==q){
		if(p+k-1<=n)cg(p,q,k);
		else cg(p,q,n-p+1),cg(1,1,k-(n-p+1));
		return;
	}
    len[1]=tt=1;
    if(n-p+1<k)len[++tt]=n-p+2;
    if(n-q+1<k)len[++tt]=n-q+2;
    if(tt==3&&len[2]>len[3])swap(len[2],len[3]);
    len[tt+1]=k+1;
    for(int i=1;i<=tt;++i)cg(Nxt(p,len[i]),Nxt(q,len[i]),len[i+1]-len[i]);
}
int main(){
	scanf("%d%d%s%s",&n,&k,a+1,b+1);int ct=0;
	for(int i=1;i<=n;++i)ct+=(a[i]=='B');
	if(ct<n-ct)swap(a,b),ct=n-ct;
	printf("%d\n",((k==1)?1:2)*(n-ct)),ct=n-ct;
	for(int i=1;i<=n;++i){
		++tot;key(tot)=rnd(),sz(tot)=1,op(tot)=(int)(a[i]-'B');
		t[tot].pos[(int)(a[i]-'B')]=1,rt=merge(rt,tot);
		++tot;key(tot)=rnd(),sz(tot)=1,op(tot)=(int)(b[i]-'B');
		t[tot].pos[(int)(b[i]-'B')]=1,rt1=merge(rt1,tot);
	}
	while(ct--){
		int s1=t[rt].pos[1],s0=t[rt1].pos[0];
		if(k==1){opr(s1,s0);continue;}
		opr(s1,Lst(s0,k+1)),opr(s1,Lst(s0,k));
	}
//	printf("%s\n%s",a+1,b+1);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4548kb

input:

6 3
BCCBCC
BBCBBC

output:

4
3 1
3 2
6 5
6 6

result:

wrong answer The final sequences are not correct!